if ( $_ =~ /^NEW YORK:\s+(\S+)/ ) { $newyork = $1; $newyork = $newyork || 'NA'; next; }
(\S+) will always match at least one character and unless you have a team named '0' (the digit zero) then 'NA' will never be assigned.
How about like this UNTESTED:
#!/usr/bin/perl use warnings; use strict; my %lookup = ( 'NEW YORK' => 1, 'MIAMI' => 1, ); my %data; while ( <DATA> ) { next unless /^([^:]+):\s+(\S+)/ && $lookup{ $1 }; $data{ $1 } = $2; } __END__ NEW YORK: knicks CHICAGO: bulls MIAMI: heat LA: lakers
In reply to Re: Please fix my writing style
by jwkrahn
in thread Please fix my writing style
by convenientstore
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |