Hidden features of Perl?
- by Adam Bellaire
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
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:
The qw operator
Letters can be used as quote delimiters in q{}-like constructs
Quoting mechanisms
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:
Autovivification
The $[ variable
tie
Dynamic Scoping
Variable swapping with a single statement
Loops and flow control:
Magic goto
for on a single variable
continue clause
Desperation mode
Regular expressions:
The \G anchor
(?{}) and '(??{})` in regexes
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:
cat files, decompressing gzips if needed
Perl Tips
See Also:
Hidden features of C
Hidden features of C#
Hidden features of C++
Hidden features of Java
Hidden features of JavaScript
Hidden features of Ruby
Hidden features of PHP
Hidden features of Python