velocitymodel:

You've already gotten some help on your coding problems. You also asked about putting the data in a different order, so here are a couple hints.

If you're going to print the records in a different order, you can't print them the instant you see them. Instead, you'll need to store them so you can rearrange them. Something like this can let you store the information:

my @records; while (<IN>) { # Write a parse_record subroutine to return the variables you want my ($NUM, $SEC, $LONG, $LAT) = parse_record($_); # Stick your variables into an array for later use push @records, [ $NUM, $SEC, $LONG, $LAT ]; }

Then, you can rearrange the records using some function, like sort:

# Sort by LONG (index 0=NUM, 1=SEC, 2=LONG, 3=LAT) my @sorted_recs = sort { $$records[$a][2] <=> $$records[$b][2] } @reco +rds;

Finally, you can print your records once you've sorted them.

for my $rec (@sorted_recs) { # pull the variables from the current record my ($NUM, $SEC, $LONG, $LAT) = @$rec; print "Num=$NUM, Sec=$SEC, Long=$LONG, Lat=$LAT\n"; }

To understand what's going on, be sure to read the documentation, such as perldsc, perlsyn, etc.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Format file2 by roboticus
in thread Format file2 by velocitymodel

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.