On Aug 10, 11:19 pm, Ryan D. [email protected] wrote:
2.text text text
your version takes a lot of memory,
Wrong.
When the number of lines to sort is small,
it uses a small amount of memory.
When the number of lines to sort is medium,
it uses a medium amount of memory.
When the number of lines to sort is large,
it uses a large amount of memory.
is slow,
Everything is relative. If its speed is compared to the
speed of other versions written in scripting languages, it
is not slow.
and doesn't properly
sort the content of the line,
Wrong.
Looking at the source code of the original poster immediately
reveals that he wants to sort only on the number at the
beginning of the line.
real 0m8.182s …
% time ruby -e ‘path = ARGV.shift; system %(sort -n “#{path}” > “#
{path}.tmp”); File.rename “#{path}.tmp”, path’ blah2.txt
Wrong.
The original poster stated:
The file is given as a command line parameter and after sorting the
entries it writes them back into this file.
Your code makes no attempt to write to the original file; it uses
a temporary file.
Furthermore, your solution won’t even run:
E:\Ruby>ruby -e 'path = ARGV.shift; system %(sort -n “#{path}”
“#{path}.tmp”); File.rename “#{path}.tmp”, path’ data
-e:1: unterminated string meets end of file
If your code is put in a file …
E:\Ruby>ruby try.rb data
Input file specified two times.
… it still won’t work.
Perhaps your attempt at a solution requires Unix, and you,
in your ignorance, or your thoughtlessness, or your
ignorance and your thoughtlessness, assumed that every
user of Ruby is a user of Unix.