What does assigning 'shift' to a variable mean?

前端 未结 4 1499
暖寄归人
暖寄归人 2021-02-01 17:57

Example:

use strict;
my $file = shift;

open(IN, $file) || die \"Unable to open $file\\n\";
open(OUT, \">$file.$$\") or die $!;

What is goin

4条回答
  •  我在风中等你
    2021-02-01 18:38

    You can read the documentation on shift. It is very clear. shift accepts an array and extracts the first element (actually removing it from the array). If you don't provide any array, it uses @ARGV (the arguments to the command line of the program) to read the data. If you're inside a function, it uses @_, namely, the parameters of the function.

    Example:

    my @array = (1, 2, 3);
    my $value = shift @array;
    print $value; # will print '1'
    

提交回复
热议问题