Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^5: printing unitialized value of the 'do BLOCK'

by LanX (Saint)
on Dec 23, 2019 at 12:54 UTC ( [id://11110548]=note: print w/replies, xml ) Need Help??


in reply to Re^4: printing unitialized value of the 'do BLOCK'
in thread printing unitialized value of the 'do BLOCK'

> Interestingly, only one of these lines gives a warning:

because the second one returns an empty list, which is a legal use of print.

C:\WINDOWS\system32>Perl -MData::Dump=pp -e "pp do{3 if ()} " undef C:\WINDOWS\system32>Perl -MData::Dump=pp -e "pp do{()} " ()

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Replies are listed 'Best First'.
Re^6: printing unitialized value of the 'do BLOCK'
by rsFalse (Chaplain) on Dec 23, 2019 at 21:22 UTC
    Thanks, now I understand the difference: in the first case '()' wanted in scalar context which was forced by 'if' (so it becomes an undefined value).

    Added:
    An 'if' forces scalar context as 'and' do, so it may be that these two are internally implemented the same.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-18 00:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found