Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: no expected 'Useless use of a constant in void context' warning for expression in return statement

by LanX (Saint)
on Dec 15, 2012 at 05:35 UTC ( [id://1008937]=note: print w/replies, xml ) Need Help??


in reply to Re^2: no expected 'Useless use of a constant in void context' warning for expression in return statement
in thread no expected 'Useless use of a constant in void context' warning for expression in return statement

I meant the "returned expression" not the "return statement"!

it's effectively

return scalar(10,20);

so no warning

DB<100> print scalar (10,20) 20

UPDATE: maybe the following is clearer,

DB<113> sub tst { 2..10 } => 0 DB<114> ($a)=tst() => 2 DB<115> $a=tst() => "" DB<116> sub tst { /2/../10/ } => 0 DB<117> $_=2 => 2 DB<118> $a=tst() => 1 DB<119> $a=tst() => 2 DB<120> $_=10 => 10 DB<121> $a=tst() => "3E0"

as you can see the range-op transforms to flip-flop-op in scalar context.

So we are not returning a list but an expression which is evaluated according to the callers context.

Cheers Rolf

  • Comment on Re^3: no expected 'Useless use of a constant in void context' warning for expression in return statement
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: no expected 'Useless use of a constant in void context' warning for expression in return statement
by ed_hoch (Sexton) on Dec 15, 2012 at 23:27 UTC
    that makes sense! thank you very much, Rolf. -Ed

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found