in reply to Using hash to parse a Flat File
If your names always have a > before them, you could set $/ to that to pick out the records. It might look something like this:
$/ = '>'; while ( <> ) { chomp; next if ! s{ \A (\S+) \s+ (?= \d ) }{}xms; my $name = $1; my @numbers = split /\D+/; my $one_number = $numbers[$href{$name} - 1]; if ( $one_number >= 20 ) { print "$name $href{$name} $one_number\n"; } }
The above code is not tested, but it should be a good start.
By the way, %href is not a very good name for a hash. It's only a little better if it's the name of a hash reference, or maybe if you're storing URLs.
Also by the way, it's better to use <code> tags only for your code and not for the whole article.
|
|---|