|
If you take a list, and use it in scalar context, you get the number of items in it. Pretty useful in a bunch of places. But what if you have one of these functions that works differently in scalar context, but you want to call the listy version and then count how many values there are? You could just use a temporary, as described above, but the true Perl master would use the goatse operator =()= (alternatively written =( )=, if you prefer authenticity over compactness). For example, to count how many times a regex matches a string: code:
|
# ¿ Jan 10, 2020 02:04 |
|
|
# ¿ Apr 29, 2024 09:32 |
|
That's exactly how it works in every other language though? Using side-effecting expressions there is weird, but that's on the person writing side-effecting expressions in that context.
|
# ¿ Jan 17, 2020 03:39 |