Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Re: uninitialized value in phonebook program

by chipmunk (Parson)
on Feb 25, 2002 at 05:09 UTC ( #147268=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: uninitialized value in phonebook program
in thread uninitialized value in phonebook program

Oh, now I got it! The warning is not actually coming from the if ($2 =~ /^0$/) { line. Unfortunately, perl sometimes reports the line number where an if block starts when the warning actually occurs later in the block. That's what is happening here.

First, you perform a regex match against $name, setting $1 and $2. Then, you perform a regex match against $2. So far, so good. Then you print out the values of $1 and $2. Oops! That second regex match you just did has wiped out the values of $1 and $2!

jeffa's node shows two ways to solve this problem. Either assign the results of the first match to new variables: my($first, $last) = $name =~ /(.+)&(.+)/;
Or replace the second match with a comparison: if ($2 eq '0') {


Comment on Re: Re: Re: uninitialized value in phonebook program
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2014-04-18 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (469 votes), past polls