in reply to Re: Regex help
in thread Regex help

Why use a hash ref when you could use a hash and simplify a little of the syntax? IMO that code would be better written:

#!/usr/bin/perl use strict; use warnings; my %fields; while (defined(my $line = <DATA>)) { chomp $line; my ($key, @data) = split ' ', $line; next if !defined $key; push @{$fields{$key}}, @data; } print "@{$fields{'TMP'}}\n"; __DATA__ KATL GFS MOS GUIDANCE 2/01/2010 1800 UTC DT /FEB 2 /FEB 3 /FEB 4 HR 00 03 06 09 12 15 18 21 00 03 06 09 12 15 18 21 00 03 06 12 18 N/X 38 47 32 55 38 TMP 47 44 41 40 39 40 42 45 43 41 37 35 33 41 50 55 50 45 42 40 45 DPT 34 33 31 32 34 36 38 38 36 34 32 30 29 29 29 28 29 30 30 32 34 CLD SC OV OV OV OV OV FW CL BK SC FW CL CL FW FW SC CL OV OV BK OV WDR 09 08 07 04 02 03 32 32 33 32 32 32 32 34 01 04 02 04 05 07 07 WSP 07 07 07 09 10 08 09 11 09 08 08 08 08 08 07 06 07 06 06 07 11 P06 79 99 30 1 1 3 2 2 5 28 48 P12 99 30 3 2 29 Q06 2 4 0 0 0 0 0 0 0 0 2 Q12 3 0 0 0 0 T06 2/13 2/ 1 2/ 4 0/ 8 0/12 0/ 0 0/ 5 0/11 0/ 2 3/ 5 T12 5/ 4 0/12 0/ 5 0/11 3/ 5 POZ 0 0 3 1 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 POS 0 0 0 0 0 0 0 0 0 2 8 13 11 0 1 0 0 0 0 1 0 TYP R R R R R R R R R R R R R R R R R R R R R SNW 0 0 CIG 8 6 5 4 3 4 4 4 6 8 8 8 8 8 8 8 8 8 8 6 4 VIS 7 7 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 7 7 4 OBV N N BR BR N BR N N N N N N N N N N N N N N BR

and the OP may find it a little easier to understand.


True laziness is hard work