new_perl
new_perl

Reputation: 7735

What's the difference between BAREWORD and *BAREWORD in 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?

Upvotes: 7

Views: 374

Answers (1)

ikegami
ikegami

Reputation: 385847

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, ...)

Upvotes: 8

Related Questions