Perl function call confused me

The perl function call confused me, can 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 it exists =>, and I think it should be ,.

+5
source share
1 answer

=>(almost) equivalent ,in Perl. (See the official documentation for differences.)

It is usually used when defining a hash to indicate the relationship between a key and a value:

my %hash = (
  'a' => 1,
  'b' => 2,
);

We could write it as my %hash = ('a', 1, 'b', 2);unchanged in behavior, but it doesn’t look so good. You can even do it my $hash = ('a', 1 => 'b', 2);, but it’s just confusing.

Similarly, in your case, you can write code as

catFiles(\@LINKFILES, "$output_prefix.links");

, =>.

, , @LINKFILES "$output_prefix.links".

+10

All Articles