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.


In reply to Re^3: Sort then conditionally sort by ig
in thread Sort then conditionally sort by lukez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.