理解一段Perl代码
我从未做过perl编程,但我正在看下面的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 $
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。很抱歉有误解。