Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Use of uninitialized value in pattern match (m//)

by graff (Chancellor)
on Mar 18, 2015 at 01:20 UTC ( [id://1120405]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Use of uninitialized value in pattern match (m//)
in thread Use of uninitialized value in pattern match (m//)

Those are actually warnings - the script keeps running, and probably does what you intended overall (whereas an error would cause the script to halt immediately). I expect that the warnings happen on the last iteration of the "for" loop:
for $line (<FILE>) {
The part in parens produces an anonymous array that the "for" will iterate over, and the last element of that array the "undef" element from the last attempt to read from the file handle and encountering 'eof'. If you used a while loop instead, you wouldn't enter the block (lines 25 and 26 would not be reached) on that last attempt to read from the file.

Replies are listed 'Best First'.
Re^4: Use of uninitialized value in pattern match (m//)
by Anonymous Monk on Mar 18, 2015 at 01:24 UTC

    The part in parens produces an anonymous array that the "for" will iterate over, and the last element of that array the "undef" element from the last attempt to read from the file handle and encountering 'eof'. If you used a while loop instead, you wouldn't enter the block (lines 25 and 26 would not be reached) on that last attempt to read from the file.

    um, none of that :) if the match fails $participant is undef , when you try to print var which is undef you get uninitialized warning

    $ perl -MData::Dump -we " open $fake, q{<}, \qq{a\nb\nc\n\n}; for(<$fa +ke>){ dd($_); }" "a\n" "b\n" "c\n" "\n"
      Thanks - that should teach me to avoid posting guesses...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-03-28 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found