Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.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_Komodo - Fatal编程技术网

理解一段Perl代码

理解一段Perl代码,perl,komodo,Perl,Komodo,我从未做过perl编程,但我正在看下面的perl代码,这让我很困惑: sub read_pds { my $bin_s; my $input_pds_file = $_[0]; open(my $fh, '<', $input_pds_file) or die "cannot open file $input_pds_file"; { local $/; $bin_s = <$fh>; } close($fh); return $

我从未做过perl编程,但我正在看下面的perl代码,这让我很困惑:

sub read_pds
{
   my $bin_s;
   my $input_pds_file = $_[0];
  open(my $fh, '<', $input_pds_file) or die "cannot open file $input_pds_file";
  {
    local $/;
    $bin_s = <$fh>;
  }
  close($fh);
  return $bin_s;
}
sub-read\u-pds
{
我的$bin_;
我的$input_pds_文件=$\u0];

open(my$fh,Perl没有您想象中的类型,但是返回的值将是一个字符串(
$input\u pds\u文件的内容
$fh
读取一行/记录,因为
$//code>(输入记录分隔符)设置为
undef
,这将是整个文件。

Perl没有您认为的类型,但是返回的值将是一个字符串(
$input\u pds\u文件的内容
$fh
读取一行/记录,因为
$//code>(输入记录分隔符)设置为
unde
,这将是整个文件。

获取传递给函数调用的第一个参数:

my $input_pds_file = $_[0];
打开要读取的文件:

open(my $fh, '<', $input_pds_file) or die "cannot open file $input_pds_file";
并将整个文件读取到变量:

$bin_s = <$fh>;

获取传递给函数调用的第一个参数:

my $input_pds_file = $_[0];
打开要读取的文件:

open(my $fh, '<', $input_pds_file) or die "cannot open file $input_pds_file";
并将整个文件读取到变量:

$bin_s = <$fh>;

所以它将返回整个文件并返回一个字符串?我不确定这个文件的内容是什么样子,因为它的扩展名是.pds,但它是否应该是Byte[]?@Californicated,您称之为
Byte[]
,perl调用string.ohk。很抱歉有误解。因此它将返回整个文件并返回字符串?我不确定此文件的内容是什么样子,因为它有扩展名.pds,但它不应该是Byte[]?@Californicated您称之为
Byte[]
,perl调用string.ohk。很抱歉有误解。