in reply to Re: Sort then conditionally sort
in thread Sort then conditionally sort

I want to thank all of you for your help on this . Hi ikegami, I think your (update code) will be easier for me to eventually understand than the other code versions. I am open to any explanation/comments 1 thing I need to mention is that the data will be in an external file. Do I need to change the way your code opens up data?
That is this part

while (<DATA>)
to something like this???
========================================================
open (my $IN, 'myfile.dat') or die "$!";
my @data = <$IN>;
close $IN;
========================================================
I hope I am saying this correctly... I will also need to have all sorted data in a different file... I think something like
open (my $OUT, ">", 'output.dat') or die "$!";
then perhaps add $OUT to your print-output code
print ("$_->[0] $_->1,$_->2\n") for @data;
to
print $OUT("$_->[0] $_->1,$_->2\n") for @data;
would that work or am I out in left field? You guys a teriffic, thank you all again...

by the way is perl the best method to do this? I am curious about why there are so many languages, if 3 or 4 can do it all....Not sure if that is true tho... thx so much everyone Luke

pps Is there a way to know when I get a response from you guys, as in an email notice? peace!!!

Replies are listed 'Best First'.
Re^3: Sort then conditionally sort
by ikegami (Patriarch) on Apr 11, 2009 at 06:52 UTC

    Why would think that reading a line from a file handle should be replaced with reading the entire file into an array and closing the file?

    By the way, my data wasn't exactly in the same format as yours. I thought the first column was actually a file name and not in the file itself. That means you'll need to adjust the input parsing and output format.

    would that work or am I out in left field?

    Yes, that's how you write to a file.

    I am curious about why there are so many languages, if 3 or 4 can do it all....

    Because no language does it all, or does it the same way.

      I was wondering how to get the <DATA> to be read in to this code. I wasnt familiar with this method. So you are saying that I can read the 2 col file line by line, with the code as is? So to invoke this code - do I do something like this> Let's say this code is saved as sort_it.pl
      Then from a cmd line I would type
      c:> perl sort_it.pl myinputfile.txt

      Is this close?
      thank you in advance...
      Im really trying to follow this stuff.

        By passing the file name like that, the contents of that file will be available with <>, which is short for <ARGV>. See perlvar for ARGV.