Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: @_ the default variable?

by wog (Curate)
on Sep 14, 2001 at 22:35 UTC ( [id://112488]=note: print w/replies, xml ) Need Help??


in reply to @_ the default variable?

@_ is only passed unchanged to functions called using a prefixing & and no () (e.g. &func). However shift is not really a function. That means you cannot call it like &shift. Shift also takes its arguments in a special way so the & syntax would not even make sense, because & ignores prototypes (which are needed to obtain this "special" treatment of arguments from perl code.)

arturo is mostly correct about what shift defaults to, but note that there are exceptions (that you are unlikely to encounter anytime soon) where shift will take @ARGV by default within a subroutine. See the docs for more details.

Replies are listed 'Best First'.
Re: Re: @_ the default variable?
by Anonymous Monk on Sep 14, 2001 at 22:50 UTC
    If shift "is not really a function", what is it? And I thought only *subroutines* were called with &. shift certainly isn't a subroutine.
      The words subroutine and function are often used interchangably in perl. (Even perlsub does it!) What I meant by calling shift "not really a function" was that it is very unlike the functions you define in your code, which have a symbol table entry and thus are associated with a package, can have coderefs be taken of them, and be aliased to other names at the symbol table entry, or imported into other packages, in addition to being callable by the & syntax.
        You mean you can't override shift like you can with other built-in functions (import into CORE:: if memory serves)?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found