in reply to Re^2: Sort then conditionally sort
in thread Sort then conditionally sort
I think you have answers to most of your questions from others by now but briefly...
Ikegami's update looks good to me.
There are many ways to do everything - a bit confusing in the beginning but good in the long run. To read your data from another file you can let some perl "magic" do it for you, perhaps something like the following:
#!/usr/local/bin/perl use strict; use warnings; foreach my $line (<>) { print "$line"; }
The above script will read every line of every file named on the command line or, if no files are named on the command line, will read from standard input (STDIN). It does nothing but print the contents of the file, but you can put anything you like inside the loop.
Alternatively, and perhaps a bit less mysteriously, you can open the file explicity yourself. The following would do it:
#!/usr/local/bin/perl use strict; use warnings; my $filename = shift; # get the filename from the command line open(my $fh, '<', $filename) or die "$filename: $!"; foreach my $line (<$fh>) { print "$line"; }
You might read open and perlopentut for more on opening files for input and output.
You may have realized that <DATA> is special: it reads the data in your program file that appears after a line containing "__DATA__" (without the quotes) or "__END__". This is convenient for test scripts and otherwise. You can read more about this in perldata.
Having some numbers in the group names won't be a problem. If you use Ikegami's examples the group names are sorted lexically. It is easier to sort them so that all the records for a group come together.
|
|---|