Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
字符串中的perl哈希对值_Perl - Fatal编程技术网

字符串中的perl哈希对值

字符串中的perl哈希对值,perl,Perl,我想知道如何将$opt{p}中的值和一个直字符串发送到子例程而不是数组 use Getopt::Std; my $opt_string = 'hdp:j:'; getopts( "$opt_string", \%opt ) or usage(); usage() if $opt{h}; } sub usage() { print STDERR << "EOF"; This program grabs the problem print req

我想知道如何将$opt{p}中的值和一个直字符串发送到子例程而不是数组

use Getopt::Std;
my $opt_string = 'hdp:j:';
getopts( "$opt_string", \%opt ) or usage();

usage() if $opt{h};
}   

sub usage()
{
        print STDERR << "EOF";
        This program grabs the problem print request and puts them in folder for investigation.
        usage: $0 [-d] [-p printer]  [-j job]   -h        : this (help) message
        -p printer: problem printer
        -j file   : problem print job id
        -d        : print debugging messages to stderr

        example: $0 -p PRINTERQ -j 76063 -d
EOF
        exit;

}

sub find_printer
{
        my $printer = $_[0] ;
        print "Looking for printer $printer .. \n";

}


find_printer( $opt{p} )  or  die "Unable to find printer";

子例程总是接收一个数组-即使它包含一个单独的参数

@@通常不是真正的数组-如果您引用它,它会暂时变为现实,它只是提供一个与其他perl语法一致的语法来访问参数。

根据perlvar[]:

在子例程中,数组@u包含传递给该子例程的参数

和perlsub[]:

传入的任何参数都会显示在数组@\。因此,如果使用两个参数调用函数,这些参数将存储在$[0]和$[1]中。数组@\是一个局部数组,但其元素是实际标量参数的别名。特别是,如果更新了元素$[0],则会更新相应的参数,如果不可更新,则会发生错误。如果参数是在调用函数时不存在的数组或散列元素,则只有在修改或引用该元素时才会创建该元素。一些早期版本的Perl创建了该元素,而不管该元素是否已分配给。分配给整个数组@会移除该别名,并且不会更新任何参数


@_绝对是一个数组:

医生希望你相信,是的。。。在这个问题的上下文中,我想知道如何在不创建数组的情况下传递参数,我认为有必要说实话,没有创建单独的数组。