What pseudo-operators exist in Perl 5?
Nice project, here are a few:
scalar x!! $value # conditional scalar include operator
(list) x!! $value # conditional list include operator
'string' x/pattern/ # conditional include if pattern
"@{[ list ]}" # interpolate list expression operator
"${\scalar}" # interpolate scalar expression operator
!! $scalar # scalar -> boolean operator
+0 # cast to numeric operator
.'' # cast to string operator
{ ($value or next)->depends_on_value() } # early bail out operator
# aka using next/last/redo with bare blocks to avoid duplicate variable lookups
# might be a stretch to call this an operator though...
sub{\@_}->( list ) # list capture "operator", like [ list ] but with aliases
In Perl these are generally referred to as "secret operators".
A partial list of "secret operators" can be had here. The best and most complete list is probably in possession of Philippe Bruhad aka BooK and his Secret Perl Operators talk but I don't know where its available. You might ask him. You can probably glean some more from Obfuscation, Golf and Secret Operators.
Don't forget the Flaming X-Wing =<>=~
.
The Fun With Perl mailing list will prove useful for your research.
The "goes to" and "is approached by" operators:
$x = 10;
say $x while $x --> 4;
# prints 9 through 4
$x = 10;
say $x while 4 <-- $x;
# prints 9 through 5
They're not unique to Perl.
From this question, I discovered the %{{}}
operator to cast a list as a hash. Useful in
contexts where a hash argument (and not a hash assignment) are required.
@list = (a,1,b,2);
print values @list; # arg 1 to values must be hash (not array dereference)
print values %{@list} # prints nothing
print values (%temp=@list) # arg 1 to values must be hash (not list assignment)
print values %{{@list}} # success: prints 12
If @list
does not contain any duplicate keys (odd-elements), this operator also provides a way to access the odd or even elements of a list:
@even_elements = keys %{{@list}} # @list[0,2,4,...]
@odd_elements = values %{{@list}} # @list[1,3,5,...]