in reply to Loading a HoH

First of all, check out `perldoc -q 'quoting.*vars'`. It will lead you to perlfaq4 and you should read that.

Second, you're nesting loops where it doesn't make sense. If you use the diamond operator, you do not have to expect $/ to be found twice in the returned string, it will be at the end of the returned string and if it isn't even there, your ate the EOF.

Third, what do you need all those temporary variables for? It is not wrong to have them, but they're quite redundant.

Fourth, what is @Messages good for?

Fifth, have a look in perlop what the /o means: you don't need it.

Sixth, '(.*)' will always match, it doesn't make much sense to use it.

# UNTESTED my @line_regexs = ( qr/(Packet ID)\s+\(hex\)\s+(\w+)\s+(Origin)\s+([\w\s]+)/, qr/(Date) \s+ \(mm\/dd\/yyyy\) \s+ (\d{2}\/\d{2}\/\d{4}) \s+ (Qualifier) \s+ (\w+) /x, # ... ); my ($count,%hash) = (1); open my $fh,'<', $path or die $!; LINE: while( <$fh> ){ chomp; foreach my $r ( @line_regexs ){ if( /$r/ ){ $hash{$count}{$1} = $2; $hash{$count}{$3} = $4; next LINE; } } $hash{ $count++ }{'Error Message'} = $_ } close $fh;
--
http://fruiture.de