Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: format conversion, please help

by farang (Chaplain)
on Apr 07, 2013 at 00:00 UTC ( [id://1027314]=note: print w/replies, xml ) Need Help??


in reply to format conversion, please help

I took a different approach, probably less elegant and certainly less flexible than others. But it does seems to work. As the choice of some variable names might indicate ( %HoA $aref ), I am relatively new to perlish ways and am just getting familiar with usage of the various data structures.

use strict; use warnings; my %HoA; while ( <DATA> ) { next if m/^\D/; # ignore lines not beginning with a digit my ( $SampleID, $Time, $A_ObsConc, $C_ObsConc, $F_ObsConc ) = unpack("A9 A8 A15 A9 A*", $_); push @{ $HoA{A} } , [ $SampleID, $Time, $A_ObsConc ]; push @{ $HoA{C} } , [ $SampleID, $Time, $C_ObsConc ]; push @{ $HoA{F} } , [ $SampleID, $Time, $F_ObsConc ]; } for my $key ( sort keys %HoA ) { for my $aref ( @{ $HoA{$key} } ) { printf("%s %6s %9s %9s\n", $key, @$aref ); } } __DATA__ A C F SampleID Time ObsConc ObsConc ObsConc 5 24 2.27E+06 687.02 32521.94 5 168 1.92E+06 525.02 22198.44 5 12 2.94E+06 896.39 41331.61 5 -0.5 2.23E+06 942.34 40616.49 5 8 4.03E+06 1371.32 45863.69 6 24 1.02E+06 1057.89 46341.04 6 168 3.14E+06 4987.32 42166.08

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1027314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found