Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Little Perl Mysteries: what's your answer?

by robartes (Priest)
on Oct 30, 2002 at 22:21 UTC ( #209262=note: print w/replies, xml ) Need Help??


in reply to Little Perl Mysteries: what's your answer?

And my 2 cents worth..
A function prototyped to accept no arguments is treated as a candidate for inlining by the Perl compiler. In this case sub foo(){2} will be inlined because it returns a constant. The snippet will thus print 2, because print foo(); is turned into print 2; by the compiler, no matter what you do to the definition of sub foo later on at runtime.
Nice one, Ovid!

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: Little Perl Mysteries: what's your answer?
by dada (Chaplain) on Oct 31, 2002 at 08:54 UTC
    and the proof is:
    c:\>perl -MO=Deparse -e "sub foo(){2};*::foo=sub(){3};print foo();" sub foo () { 2; } *foo = sub () { 3; } ; print 2; -e syntax OK

    cheers,
    Aldo

    King of Laziness, Wizard of Impatience, Lord of Hubris

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-06-30 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (97 votes). Check out past polls.

    Notices?