Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Please fix my writing style

by jwkrahn (Abbot)
on Nov 22, 2008 at 02:10 UTC ( [id://725274]=note: print w/replies, xml ) Need Help??


in reply to Please fix my writing style

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://725274]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-25 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found