A perl function call confused me, could anyone help me?
catFiles
called like this:
catFiles( \@LINKFILES => "$output_prefix.links" );
catFiles
function define:
sub catFiles {
unlink("$_[1]") if(exists $_[1]);
system qq( cat "$_" >> "$_[1]" ) for @{$_[0]};
}
I don't know why there are =>
there which I think it should be a ,
.
=>
is (almost) equivalent to ,
in Perl. (See the "official" documentation for the differences.)
Usually it's used when defining a hash to indicate the relationship between key and value:
my %hash = (
'a' => 1,
'b' => 2,
);
We could write it as my %hash = ('a', 1, 'b', 2);
with no change in behavior but that doesn't look as nice. You could even do my $hash = ('a', 1 => 'b', 2);
but that's just confusing.
Similarly, in your case you could write the code as
catFiles(\@LINKFILES, "$output_prefix.links");
and it would do the same thing as the =>
version.
Here it's getting used as syntactic sugar, I guess to indicate that the contents of @LINKFILES
will get concatenated into "$output_prefix.links"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With