简体   繁体   中英

What's the role of “* *” in this Perl script?

I have this shell script:

eval{print "Just ";} * * {print "Another ";} * * {print "Perl ";} * * {print "Hacker\n";}

and more variants:

@${print "Just ";} * * {print "Another ";} * * {print "Perl ";} * * {print "Hacker\n";}
$${print "Just ";} * * {print "Another ";} * * {print "Perl ";} * * {print "Hacker\n";}
do{print "Just ";} * * {print "Another ";} * * {print "Perl ";} * * {print "Hacker\n";}
$#{print "Just ";} * * {print "Another ";} * * {print "Perl ";} * * {print "Hacker\n";}

What does * * do? (It also works if I change * * to & & .)

The first * of each pair is multiplication; the second is a glob dereference. So nothing very useful.

With & & the first is bitwise and and the second is a subroutine dereference (and call). I don't know why using the canonical true value (returned by print) as a code ref and calling it doesn't error; I would have expected &{!0} to error like &{"1"} does with Undefined subroutine &main::1 ; instead it seems to be a no-op.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM