What does assigning 'shift' to a variable mean?

前端 未结 4 1502
暖寄归人
暖寄归人 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:24

    shift uses the @_ variable which contains the values passed to a function or shift uses @ARGV for the values passed to the script itself if shift is referenced outside of a function.

    ONE WORD OF CAUTION: It is probably wise, especially in Windows where many paths contain spaces, to put the filename and path in single quotes when you pass it to the script or function. This will tell Perl that you are passing it a single scalar value rather than an array of values. You can use double quotes if you want to interpolate part of the name. For example:

    my $path = 'C:\Goat Kids';
    func("$path\\goat.txt");
    

    Or, from the command line if you are passing the filename directly to the script:

    perl goat.pl "C:\Goat Kids\goat.txt"
    

提交回复
热议问题