Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Error Unitialized value and use

by AnomalousMonk (Archbishop)
on Dec 08, 2015 at 06:05 UTC ( [id://1149643]=note: print w/replies, xml ) Need Help??


in reply to Error Unitialized value and use

... it didn't work.

Exactly what is "it"? Exactly how did it "not work"?

... my variables are unintilized when I initilize them at the beginning.

You assign values at the beginning, but then you assign again from the result of a match, and that's probably where the undefined values come from: regex captures return undef when the match fails. (Update: More precisely, a failed match in list context, as below and in the OPed code, returns an empty list, which, when assigned to scalar variables, yields undefs.) You have to test the success of the match somehow:

c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'eks---wye'; ;; my $found = my ($x, $y) = $s =~ m{ \A (eks) .* (wye) \z }xms; if ($found) { print qq{A: found '$x' and '$y'}; } else { print 'A: found nada'; } ;; $s = uc $s; ;; if (my ($xx, $yy) = $s =~ m{ (EKS) .* (WYE) }xms) { print qq{B: found '$xx' and '$yy'}; } else { print 'B: found nada'; } " A: found 'eks' and 'wye' B: found 'EKS' and 'WYE'
Play with that, change the string value and the match regexes, until you're confident of what's going on. (Of course, there are other ways to test match success.) The usual links: perlre, perlretut, and perlrequick.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-29 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found