Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: need help on declaring variables

by hipowls (Curate)
on Mar 03, 2008 at 09:35 UTC ( [id://671617]=note: print w/replies, xml ) Need Help??


in reply to need help on declaring variables

When using regular expressions it is usually a good idea to put them in a condition.

if ( my ( $raw_dt, $refs ) = /^(.*) UTC.*refs = (\d+)$/ ) { my $dt = $Strp->parse_datetime($raw_dt); ... } else { # possible error condition }
The greater danger of your code, apart from using uninitialized $1 and $2, is using an initialized $1 and $2 from a previous match. The capture buffer variables $1 etc are not reset to undef when a match fails so you may produce erroneous output without any outward sign.

Log In?
Username:
Password:

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

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

    No recent polls found