原文链接:https://stackoverflow.com/questions/7082811/what-does-assigning-shift-to-a-variable-mean/7082897
Example:
use strict;
my $file = shift;
open(IN, $file) || die "Unable to open $file\n";
open(OUT, ">$file.$$") or die $!;
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.