Hidden features of Perl? -
what useful esoteric language features in perl you've been able employ useful work?
guidelines:
- try limit answers perl core , not cpan
- please give example , short description
hidden features found in other languages' hidden features:
(these corion's answer)
- c
- duff's device
- portability , standardness
- c#
- quotes whitespace delimited lists , strings
- aliasable namespaces
- java
- static initalizers
- javascript
- functions first class citizens
- block scope , closure
- calling methods , accessors indirectly through variable
- ruby
- defining methods through code
- php
- pervasive online documentation
- magic methods
- symbolic references
- python
- one line value swapping
- ability replace core functions own functionality
other hidden features:
operators:
- the bool quasi-operator
- the flip-flop operator
- also used list construction
- the
++
, unary-
operators work on strings - the repetition operator
- the spaceship operator
- the || operator (and // operator) select set of choices
- the diamond operator
- special cases of
m//
operator - the tilde-tilde "operator"
quoting constructs:
syntax , names:
- there can space after sigil
- you can give subs numeric names symbolic references
- legal trailing commas
- grouped integer literals
- hash slices
- populating keys of hash array
modules, pragmas, , command-line options:
- use strict , use warnings
- taint checking
- esoteric use of -n , -p
- cpan
overload::constant
- io::handle module
- safe compartments
- attributes
variables:
loops , flow control:
regular expressions:
other features:
- the debugger
- special code blocks such begin, check, , 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 errors
other tricks, , meta-answers:
see also:
the flip-flop operator useful skipping first iteration when looping through records (usually lines) returned file handle, without using flag variable:
while(<$fh>) { next if 1..1; # skip first record ... }
run perldoc perlop
, search "flip-flop" more information , examples.
Comments
Post a Comment