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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |