Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between BAREWORD and *BAREWORD in Perl?

Tags:

perl

my $childpid = open3(HIS_IN, HIS_OUT, HIS_ERR, $cmd, @args);

my $childpid = open3(*HIS_IN, *HIS_OUT, *HIS_ERR, $cmd, @args);

It seems the above both works for my application.

What's the difference between BAREWORD and *BAREWORD in Perl?

like image 940
new_perl Avatar asked Sep 20 '11 05:09

new_perl


1 Answers

The meaning of a bareword varies. Most of the time, a bareword is a function call.

sub foo { say "Hello"; }
foo;

Sometimes, it's a string literal.

$x{foo}    # $x{"foo"}

In yet other circumstances, it produces a typeglob.

print STDOUT "foo";   # print { *STDOUT } "foo";

In this case,

open3(HIS_IN, HIS_OUT, HIS_ERR, ...)

is equivalent to

open3("HIS_IN", "HIS_OUT", "HIS_ERR", ...)

but open3 uses that string as the name of a glob in the caller's package, so the above is functionally equivalent to

open3(*HIS_IN, *IS_OUT, *HIS_ERR, ...)
like image 157
ikegami Avatar answered Sep 28 '22 09:09

ikegami