Perldoc Search: "@_" perl-5.20.1

search official POD


28 PODs, 154 LINEs found.
perlsub.pod
37 :         &NAME;         # Makes current @_ visible to called subroutine.
44 :     Any arguments passed in show up in the array @_. (They may also show up in lexical variables introduced by a signature; see "Signatures" below.) Therefore, if you called a function with two arguments, those would be stored in $_[0] and $_[1]. The array @_ is a local array, but its elements are aliases for the actual scalar parameters. In particular, if an element $_[0] is updated, the corresponding argument is updated (or an error occurs if it is not updatable). If an argument is an array or hash element which did not exist when the function was called, that element is created only when (and if) it is modified or a reference to it is taken. (Some earlier versions of Perl created the element whether or not the element was assigned to.) Assigning to the whole array @_ removes that aliasing, and does not update any arguments.
55 :             my $max = shift(@_);
56 :             foreach $foo (@_) {
89 :             my($key, $value) = @_;
93 :     Because the assignment copies the values, this also has the effect of turning call-by-reference into call-by-value. Otherwise a function is free to do in-place modifications of @_ and change its caller's values.
97 :             for (@_) { tr/a-z/A-Z/ }
109 :             my @parms = @_;
114 :     Notice how this (unprototyped) function doesn't care whether it was passed real scalars or arrays. Perl sees all arguments as one big, long, flat parameter list in @_. This is one area where Perl's simple argument-passing style shines. The "upcase()" function would work perfectly well without changing the "upcase()" definition even if we fed it things like this:
127 :     Subroutines may be called recursively. If a subroutine is called using the "&" form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead. This is an efficiency mechanism that new users may wish to avoid.
135 :         &foo;               # foo() get current args, like foo(@_) !!
144 :           my ($x) = @_;
198 :             die "Too many arguments for subroutine" unless @_ <= 2;
199 :             die "Too few arguments for subroutine" unless @_ >= 2;
278 :     When using a signature, the arguments are still available in the special array variable @_, in addition to the lexical variables of the signature. There is a difference between the two ways of accessing the arguments: @_ *aliases* the arguments, but the signature variables get *copies* of the arguments. So writing to a signature variable only changes that variable, and has no effect on the caller's variables, but writing to an element of @_ modifies whatever the caller used to supply that argument.
733 :             local(*someary) = @_;
807 :             foreach $aref ( @_ ) {
818 :             foreach $href (@_) {
823 :             return grep { $seen{$_} == @_ } keys %seen;
834 :     That syntax simply won't work. It sets just @a or %a and clears the @b or %b. Plus the function didn't get passed into two separate arrays or hashes: it got one long list in @_, as always.
841 :             my ($cref, $dref) = @_;
854 :             local (*c, *d) = @_;
919 :     Any backslashed prototype character represents an actual argument that must start with that character (optionally preceded by "my", "our" or "local"), with the exception of "$", which will accept any scalar lvalue expression, such as "$foo = 7" or "my_function()->[0]". The value passed as part of @_ will be a reference to the actual argument given in the subroutine call, obtained by applying "\" to that argument.
951 :             push @$aref, @_;
972 :             my($try,$catch) = @_;
987 :     That prints "unphooey". (Yes, there are still unresolved issues having to do with visibility of @_. I'm ignoring that question for the moment. (But note that if we make @_ lexically scoped, those anonymous subroutines can act like closures... (Gee, is this sounding a little Lispish? (Never mind.))))
994 :             foreach $_ (@_) {
1016 :     Then you've just supplied an automatic "scalar" in front of their argument, which can be more than a bit surprising. The old @foo which used to hold one thing doesn't get passed in. Instead, "func()" now gets passed in a 1; that is, the number of elements in @foo. And the "split" gets called in scalar context so it starts scribbling on your @_ parameter list. Ouch!
1150 :             return unless @_;
1153 :             $pkg->export($where, $sym, @_);
1184 :     "require" has special additional dark magic: if you invoke your "require" replacement as "require Foo::Bar", it will actually receive the argument "Foo/Bar.pm" in @_. See "require" in perlfunc.
1200 :             system($program, @_);
perlfunc.pod
315 :         Here, $subroutine is the function that the caller called (rather than the function containing the caller). Note that $subroutine may be "(eval)" if the frame is not a subroutine call, but an "eval". In such a case additional elements $evaltext and $is_require are set: $is_require is true if the frame is created by a "require" or "use" statement, $evaltext contains the text of the "eval EXPR" statement. In particular, for an "eval BLOCK" statement, $subroutine is "(eval)", but $evaltext is undefined. (Note also that each "use" statement creates a "require" frame inside an "eval EXPR" frame.) $subroutine may also be "(unknown)" if this particular subroutine happens to have been deleted from the symbol table. $hasargs is true if a new instance of @_ was set up for the frame. $hints and $bitmask contain pragmatic hints that the caller was compiled with. $hints corresponds to $^H, and $bitmask corresponds to "${^WARNING_BITS}". The $hints and $bitmask values are subject to change between versions of Perl, and are not meant for external use.
323 :         Be aware that setting @DB::args is *best effort*, intended for debugging or generating backtraces, and should not be relied upon. In particular, as @_ contains aliases to the caller's arguments, Perl does not take a copy of @_, so @DB::args will contain modifications the subroutine makes to @_ or its contents, not the original values at call time. @DB::args, like @_, does not hold explicit references to its elements, so under certain cases its elements may have become freed and reallocated for other variables or temporary values. Finally, a side effect of the current implementation is that the effects of "shift @_" can *normally* be undone (but not "pop @_" or other splicing, *and* not if a reference to @_ has been taken, *and* subject to the caveat about reallocated elements), so @DB::args is actually a hybrid of the current state and initial state of @_. Buyer beware.
590 :             sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
707 :             die @_ if $^S;
1119 :                 my ($fh) = @_;
1127 :                 my ($fh) = @_;
1414 :         The "goto &NAME" form is quite different from the other forms of "goto". In fact, it isn't a goto in the normal sense at all, and doesn't have the stigma associated with other gotos. Instead, it exits the current subroutine (losing any changes set by local()) and immediately calls in its place the named subroutine using the current value of @_. This is used by "AUTOLOAD" subroutines that wish to load another subroutine and then pretend that the other subroutine had been called in the first place (except that any modifications to @_ in the current subroutine are propagated to the other subroutine.) After the "goto", not even "caller" will be able to tell that this routine was called first.
1974 :                 my($filename, $input) = @_;
2614 :         Returns the undefined value if the array is empty, although this may also happen at other times. If ARRAY is omitted, pops the @ARGV array in the main program, but the @_ array in subroutines, just like "shift".
2650 :         Equivalent to "print FILEHANDLE sprintf(FORMAT, LIST)", except that $\ (the output record separator) is not appended. The FORMAT and the LIST are actually parsed as a single list. The first argument of the list will be interpreted as the "printf" format. This means that "printf(@_)" will use $_[0] as the format. See sprintf for an explanation of the format argument. If "use locale" (including "use locale ':not_characters'") is in effect and POSIX::setlocale() has been called, the character used for the decimal separator in formatted floating-point numbers is affected by the LC_NUMERIC locale setting. See perllocale and POSIX.
2918 :                 my ($filename) = @_;
3004 :                 my ($coderef, $filename) = @_;  # $coderef is \&my_sub
3012 :                 my ($arrayref, $filename) = @_;
3024 :                 my ($self, $filename) = @_;
3177 :                 my @fhlist = @_;
3268 :         Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down. If there are no elements in the array, returns the undefined value. If ARRAY is omitted, shifts the @_ array within the lexical scope of subroutines and formats, and the @ARGV array outside a subroutine and also within the lexical scopes established by the "eval STRING", "BEGIN {}", "INIT {}", "CHECK {}", "UNITCHECK {}", and "END {}" constructs.
3364 :         If the subroutine's prototype is "($$)", the elements to be compared are passed by reference in @_, as for a normal subroutine. This is slower than unprototyped subroutines, where the elements to be compared are passed into the subroutine as the package global variables $a and $b (see example below). Note that in the latter case, it is usually highly counter-productive to declare $a and $b as lexicals.
3513 :               while (my @next_n = splice @_, 0, $n) {
4455 :                 my($what,$where,$howmuch) = @_;
perlcall.pod
107 :     Whenever a Perl subroutine is called using one of the *call_** functions, it is assumed by default that parameters are to be passed to the subroutine. If you are not passing any parameters to the Perl subroutine, you can save a bit of time by setting this flag. It has the effect of not creating the @_ array for the Perl subroutine.
111 :     In fact, what can happen is that the Perl subroutine you have called can access the @_ array from a previous Perl subroutine. This will occur when the code that is executing the *call_** function has itself been called from another Perl subroutine. The code below illustrates this
114 :           { print "@_\n"  }
125 :     What has happened is that "fred" accesses the @_ array which belongs to "joe".
209 :             my($s, $n) = @_;
246 :     3.   Any parameters to be pushed onto the stack should be bracketed by the "PUSHMARK" and "PUTBACK" macros. The purpose of these two macros, in this context, is to count the number of parameters you are pushing automatically. Then whenever Perl is creating the @_ array for the subroutine, it knows how big to make it.
285 :             my($a, $b) = @_;
323 :     1.   The only flag specified this time was G_SCALAR. That means that the @_ array will be created and that the value returned by *Adder* will still exist after the call to *call_pv*.
352 :            my($a, $b) = @_;
505 :             my ($a, $b) = @_;
588 :             my($a,$b) = @_;
734 :             my(@list) = @_;
762 :                 bless [@_]
767 :                 my ($self, $index) = @_;
773 :                 my($class) = @_;
1056 :             my($handle, $buffer) = @_;
1283 :     It is usual to pass parameters using global variables (typically $_ for one parameter, or $a and $b for two parameters) rather than via @_. (It is possible to use the @_ mechanism if you know what you're doing, though there is as yet no supported API for it. It's also inherently slower.)
perltie.pod
68 :                 croak "usage error" if @_;
85 :                 croak "usage error" if @_;
150 :               if ( @_ || $elemsize =~ /\D/ ) {
179 :               my( $index, $value ) = @_;
266 :               my @list = @_;
293 :               my @list = @_;
319 :               if ( @_ ) {
321 :                 @list   = @_;
375 :         sub debug { $DEBUG = @_ ? shift : 1 }
390 :                 croak "usage: @{[&whowasi]} [USER [DOTDIR]]" if @_;
477 :                 $self->{CLOBBER} = @_ ? shift : 1;
604 :                 my($buf,$len,$offset) = @_;
611 :             sub PRINT { $r = shift; $$r++; print join($,,map(uc($_),@_)),$\ }
621 :                 print sprintf($fmt, @_);
630 :                 my(undef,$len,$offset) = @_;
796 :          my ($obj,$count) = @_;
perlref.pod
59 :             sub hashem {        { @_ } }   # silently wrong
60 :             sub hashem {       +{ @_ } }   # ok
61 :             sub hashem { return { @_ } }   # ok
65 :             sub showem {        { @_ } }   # ambiguous (currently ok,
67 :             sub showem {       {; @_ } }   # ok
68 :             sub showem { { return @_ } }   # ok
348 :         $array{ shift @_ }
367 :             *$name = *{uc $name} = sub { "<FONT COLOR='$name'>@_</FONT>" };
perlfilter.pod
147 :           my ($type) = @_;
153 :           my ($self) = @_;
242 :            my ($type) = @_;
261 :            my ($self) = @_;
298 :            my ($self) = @_;
332 :     Here is an interesting idea that doesn't involve the Debug filter. Currently Perl subroutines have fairly limited support for formal parameter lists. You can specify the number of parameters and their type, but you still have to manually take them out of the @_ array yourself. Write a source filter that allows you to have a named parameter list. Such a filter would turn this:
341 :            my (@rest) = @_;
perlobj.pod
138 :     Just as with any Perl subroutine, all of the arguments passed in @_ are aliases to the original argument. This includes the object itself. If you assign directly to $_[0] you will change the contents of the variable that holds the reference to the object. We recommend that you don't do this unless you know exactly what you're doing.
291 :           my ( $path, $data ) = @_;
309 :           my ( $path, $data ) = @_;
314 :           return $class->SUPER::new(@_);
348 :           if (@_) {
perlipc.pod
616 :         sub logmsg { print "$0 $$: @_ at ", scalar localtime(), "\n" }
657 :         sub logmsg { print "$0 $$: @_ at ", scalar localtime(), "\n" }
713 :             unless (@_ == 0 && $coderef && ref($coderef) eq "CODE") {
810 :         sub logmsg { print "$0 $$: @_ at ", scalar localtime(), "\n" }
852 :             unless (@_ == 0 && $coderef && ref($coderef) eq "CODE") {
perlop.pod
421 :             my ($class, $init_fields) = @_;
435 :             my ($class, $init_fields) = @_;
930 :     Interpolating an array or slice interpolates the elements in order, separated by the value of $", so is equivalent to interpolating "join $", @array". "Punctuation" arrays such as "@*" are usually interpolated only if the name is enclosed in braces "@{*}", but the arrays @_, "@+", and "@-" are interpolated even without braces.
985 :                     } @_;
1859 :             my ($X, $Y, $POINTS) = @_;
perlvar.pod
29 :     Before you continue, note the sort order for variables. In general, we first list the variables in case-insensitive, almost-lexigraphical order (ignoring the "{" or "^" preceding words, as in "${^UNICODE}" or $^T), although $_ and @_ move up to the top of the pile. For variables with the same identifier, we list it in order of scalar, array, hash, and bareword.
70 :     @_      Within a subroutine the array @_ contains the parameters passed to that subroutine. Inside a subroutine, @_ is the default array for the array operators "push", "pop", "shift", and "unshift".
250 :                     my($sig) = @_;
1000 :                         my ($class, $time) = @_;
perlthrtut.pod
119 :             my @InboundParameters = @_;
190 :            my ($message) = @_;
411 :             my $SubNumber = shift(@_);
530 :       11     my ($upstream, $cur_prime) = @_;
perlintro.pod
148 :         There are a couple of special arrays too, such as @ARGV (the command line arguments to your script) and @_ (the arguments passed to a subroutine). These are documented in perlvar.
460 :     What's that "shift"? Well, the arguments to a subroutine are available to us as a special array called @_ (see perlvar for more on that). The default argument to the "shift" function just happens to be @_. So "my $logmessage = shift;" shifts the first item off the list of arguments and assigns it to $logmessage.
462 :     We can manipulate @_ in other ways too:
464 :      my ($logmessage, $priority) = @_;       # common
perlembed.pod
468 :             my ($a, $b) = @_;
545 :          my($string) = @_;
556 :          my($filename, $delete) = @_;
672 :          print "foo says: @_\n";
perldiag.pod
175 :         (S debugging) This indicates that something went wrong and Perl got *very* confused about @_ or @DB::args being tied.
2124 :             my $foo, $bar = @_;
2128 :             my ($foo, $bar) = @_;
perldata.pod
333 :         my($a, $b, %rest) = @_;
547 :             open my $fh, "@_"
548 :                  or die "Can't open '@_': $!";
perlvms.pod
260 :                 my($user,$passwd) = @_;
334 :                 foreach $file (@_) {
perllol.pod
220 :             dumpValue $prettily @_;
300 :                 $y_lo, $y_hi) = @_;
perlunicode.pod
809 :           my($self,$name,$value) = @_;
875 :            my($self, $sth, $what) = @_;
perlform.pod
255 :             croak "usage: swrite PICTURE ARGS" unless @_;
258 :             formline($format,@_);
perlpragma.pod
47 :             my ($l, $r) = @_;
57 :             my ($class, $value) = @_;
perlre.pod
1378 :           die "No argument to customre::import allowed" if @_;
perldebtut.pod
537 :             BEGIN { $SIG{__DIE__} = sub { require Carp; Carp::confess(@_) } }
perlsyn.pod
431 :     The "goto"-&NAME form is highly magical, and substitutes a call to the named subroutine for the currently running subroutine. This is used by "AUTOLOAD()" subroutines that wish to load another subroutine and then pretend that the other subroutine had been called in the first place (except that any modifications to @_ in the current subroutine are propagated to the other subroutine.) After the "goto", not even "caller()" will be able to tell that this routine was called first.
perldtrace.pod
8 :         # perl -E 'sub outer { inner(@_) } sub inner { say shift } outer("hello")'
perlsec.pod
108 :             return ! eval { eval("#" . substr(join("", @_), 0, 0)); 1 };
perlcheat.pod
71 :       11 blksz               3..10 only     @_    subroutine args
perldebug.pod
535 :     If you alter your @_ arguments in a subroutine (such as with "shift" or "pop"), the stack backtrace will not show the original values.
perlperf.pod
206 :             my %report = @_;
<< Back to Perldoc Search