in reply to formatted hash problem
I do not entirely follow how your input maps to your output, even after reading the previous thread. Based upon my best guess, you should use a hash of arrays of arrays - see perllol for info on more advanced data structures. Note that while Perl would handle the scientific notation value with no difficulty, it doesn't matter since you are not doing math with it. As far as Perl is concerned, this is just a series of space-delimited strings. Does this do what you intend?
#!/usr/bin/perl use strict; use warnings; my %relays; while (<DATA>) { chomp; my @result = split /\s/; my $id = shift @result; for my $i (0 .. $#result) { push @{$relays{$id}[$i]}, $result[$i]; } } for my $id (keys %relays) { for my $field_ref ($relays{$id}) { for my $values_ref (@$field_ref) { print "$id @$values_ref\n"; } } } __DATA__ relay01 238 933 set relay02 238 934 9876536 2345.56 relay01 238 934 reset relay02 239 935 876555 23456.88 relay01 239 999 initiate relay03 240 877 899998 87698 relay03 241 888 98989898 3.34e-10
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: formatted hash problem
by AnomalousMonk (Archbishop) on Feb 05, 2010 at 19:41 UTC | |
|
Re^2: formatted hash problem
by Spooky (Beadle) on Feb 05, 2010 at 15:48 UTC | |
by kennethk (Abbot) on Feb 05, 2010 at 16:53 UTC | |
|
Re^2: formatted hash problem
by Spooky (Beadle) on Feb 19, 2010 at 17:27 UTC | |
by kennethk (Abbot) on Feb 19, 2010 at 22:43 UTC | |
by Spooky (Beadle) on Feb 20, 2010 at 18:45 UTC | |
by kennethk (Abbot) on Feb 22, 2010 at 15:49 UTC |