What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
Guidelines:
- Try to limit answers to the Perl core and not CPAN
- Please give an example and a short description
Hidden Features also found in other languages' Hidden Features:
(These are all from Corion's answer)
- C
- Duff's Device
- Portability and Standardness
- C#
- Quotes for whitespace delimited lists and strings
- Aliasable namespaces
- Java
- Static Initalizers
- JavaScript
- Functions are First Class citizens
- Block scope and closure
- Calling methods and accessors indirectly through a variable
- Ruby
- Defining methods through code
- PHP
- Pervasive online documentation
- Magic methods
- Symbolic references
- Python
- One line value swapping
- Ability to replace even core functions with your own functionality
Other Hidden Features:
Operators:
- The bool quasi-operator
- The flip-flop operator
- Also used for list construction
- The
++
and unary-
operators work on strings - The repetition operator
- The spaceship operator
- The || operator (and // operator) to select from a set of choices
- The diamond operator
- Special cases of the
m//
operator - The tilde-tilde "operator"
Quoting constructs:
Syntax and Names:
- There can be a space after a sigil
- You can give subs numeric names with symbolic references
- Legal trailing commas
- Grouped Integer Literals
- hash slices
- Populating keys of a hash from an array
Modules, Pragmas, and command-line options:
- use strict and use warnings
- Taint checking
- Esoteric use of -n and -p
- CPAN
overload::constant
- IO::Handle module
- Safe compartments
- Attributes
Variables:
Loops and flow control:
Regular expressions:
Other features:
- The debugger
- Special code blocks such as BEGIN, CHECK, and END
- The
DATA
block - New Block Operations
- Source Filters
- Signal Hooks
- map (twice)
- Wrapping built-in functions
- The
eof
function - The
dbmopen
function - Turning warnings into errors
Other tricks, and meta-answers:
See Also: