Hidden features of Perl?
Posted
by Adam Bellaire
on Stack Overflow
See other posts from Stack Overflow
or by Adam Bellaire
Published on 2008-10-02T11:49:22Z
Indexed on
2010/03/19
17:01 UTC
Read the original article
Hit count: 564
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:
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:
© Stack Overflow or respective owner