Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by rsFalse (Chaplain)
on Dec 18, 2019 at 22:50 UTC ( [id://11110359]=note: print w/replies, xml ) Need Help??


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

Thanks for pointing this out!
I haven't tested much, only tested with plain '1'.
my $x = 1; print "[$_]" for do{ unless( $x ){ 5 } }, do{ unless( 1 ){ 6 } }, ;
Output:
[1] []

Replies are listed 'Best First'.
Re^8: printing unitialized value of the 'do BLOCK'
by choroba (Cardinal) on Dec 19, 2019 at 15:07 UTC
    I'm getting [1][1] from the above code. What version of perl do you run?
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      $ for v in 30 28 26 24 22 20 18 16 14 12 10; do printf '5.%s: ' $v 5.${v}t/bin/perl a.pl done 5.30: [1][1] 5.28: -bash: 5.28t/bin/perl: No such file or directory 5.26: [1][1] 5.24: [1][1] 5.22: [1][] 5.20: [1][] 5.18: [1][] 5.16: [1][] 5.14: [1][] 5.12: [1][] 5.10: [1][]

      I think it's an unintentional change that resulted from fixing this.

Re^8: printing unitialized value of the 'do BLOCK'
by ikegami (Patriarch) on Dec 18, 2019 at 23:04 UTC

    And there we go. The reason the value is only defined when the last statement is an expression.

      I thought that '1' is also expression.

        But the return value is only defined when the last statement is an expression. The last statement is an unless statement, so the return value is undefined.

        We were discussing what value is returned even though it's undefined. But that's always dangerous. As you've pointed out, it doesn't always work.

        Update: Fixed typo (until=>unless)

Log In?
Username:
Password:

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

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

    No recent polls found