Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: sub execution order aka missing semicolon after sub call

by haukex (Archbishop)
on Apr 06, 2016 at 15:30 UTC ( [id://1159725]=note: print w/replies, xml ) Need Help??


in reply to sub execution order aka missing semicolon after sub call

Hi jmaas,

Because in Perl parentheses are often optional, sub_A sub_B; means sub_A(sub_B()); (no matter if it's split on two lines), i.e. the return value of a call to sub_B() is being used as the argument(s) to sub_A(), which means sub_B() has to be called first. B::Deparse can show you this (edited slightly for brevity):

$ perl -MO=Deparse,-p -e 'sub a {} sub b {} a; b;' sub a { } sub b { } a(); b(); $ perl -MO=Deparse,-p -e 'sub a {} sub b {} a b;' sub a { } sub b { } a(b());

Hope this helps,
-- Hauke D

Log In?
Username:
Password:

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

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

    No recent polls found