Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
There's more than one way to do things
 
PerlMonks  

Re: NEWBIE Brain Teaser #2, by nysus

by merlyn (Sage)
on Apr 15, 2001 at 17:01 UTC ( [id://72674]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to NEWBIE Brain Teaser #2, by nysus

Hint: The answer to Part C will depend on whether you're on 5.5 or 5.6.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: NEWBIE Brain Teaser #2, by nysus
by Eureka_sg (Monk) on Apr 15, 2001 at 17:07 UTC

    SPOILER ALERT!

    From my understanding, the existing @_ will be passed by default when you use &subroutine instead. Is there a change in 5.6?

    Edit: chipmunk 2001-04-16

      You are correct that @_ will be passed to a subroutine if you call it without using the parenthesis. This is true of both 5.6 and 5.005 at least.

      However the result of the attempted assignment of a list to $_ differ depending on Perl version, and this DOES affect the output you will see.

        However the result of the attempted assignment of a list to $_ differ depending on Perl version, and this DOES affect the output you will see.
        Perl never attempts to assign a list to $_. Ever.

        Understanding is demonstrated when correct phrasing is used. {grin}

        -- Randal L. Schwartz, Perl hacker

Re: Re: NEWBIE Brain Teaser #2, by nysus
by artist (Parson) on Apr 16, 2001 at 12:07 UTC
    $_ = qw(nothing nothing)
    Translates to:
    1. Under 5.005
    @_ = qw(nothing nothing)
    2. Under 5.6
    No effect on @_;
    Resulting
    call for &subroutine
    1. Under 5.005
    prints "..nothing..nothing"
    2. Under 5.6
    prints "..alpha ..omega"

    Try:

    print qw(1 2 3)[0]
    under 5.005 and 5.6.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://72674]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.