The Goatse Pseudo-operator takes a list on its right hand side and returns the number of elements in the list in scalar context (and an empty list in list context) . my $str = "1,2 cha cha cha, 3,4 cha cha cha"; my $count =()= $str =~ /\d/g; print $count; Output will be 4. (1,2,3 & 4).
The Goatse Pseudo-Operator takes a list on its right hand side and returns the number of elements in the list in scalar context (and an empty list in list context).
my $str = "1,2 cha cha cha, 3,4 cha cha cha";
my $count =()= $str =~ /\d/g;
print $count;
Output will be 4. (1,2,3 & 4)
The actual operators and terms involved are (from left to right) scalar assignment: =, the empty list term: (), and list assignment: =. It takes advantage of the fact that list assignment returns the number of items on the right hand side when called in scalar context:
my $count = my ($x, $y, $z) = ("a" .. "z");
print "$count $x $y $z\n";
Output will be: 26 a b c
By specifying an empty list, you spare perl
from having to copy the values in the list, but it still returns the number of elements on the right hand side. The following two lines are identical in results:
my $count = () = ("a" .. "z"); #formatted as separate operators
my $count =()= ("a" .. "z"); #formatted as the goatse operator
The name comes from a picture distributed by a website designed to shock people. Searching for the term may provide more insight into the name choice, but it is not advised.