Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Hidden features of Perl

by vxp (Pilgrim)
on Jun 22, 2009 at 00:48 UTC ( #773443=perlmeditation: print w/replies, xml ) Need Help??

I stumbled upon this list of "hidden features of perl" and thought it'd a good idea if I got some of your replies as well!

Just as on the site, here a few "requirements":

Try to limit answers the Perl core and not CPAN

Please give an example and a short description

Replies are listed 'Best First'.
Re: Hidden features of Perl
by eyepopslikeamosquito (Bishop) on Jun 22, 2009 at 23:44 UTC

    Some old PM nodes I remember that seem relevant:

    From The Lighter Side of Perl Culture (Part IV): Golf, some "hidden golfing features":

    Golfing Technique Inventor Year ----------------- -------- ---- @{[]} aka baby cart The Larry or 1994 The Schwartz }{ aka eskimo greeting The Abigail late 1990s ~~ aka inchworm ??? ~- aka inchworm-on-a-stick The Hospel 2002 $_ x= boolean expression The Larry early 1990s y///c aka Abigail's Length Horror The Hall 1996 stuff value into $\ for printing The van der Pijll 2001 }for(...){ variation of eskimo The Hospel 2001 --$| magical flip-flop The Hospel 2002 \$h{X} is one less than ++$h{X} aka Thelen's Device The Thelen 2002

    Update: BooK has recently popularized a new set of secret operators, the screwdriver operators:

    -=! and -=!! - flathead +=! and +=!! - phillips *=! and *=!! - torx x=! and x=!! - pozidriv ( This is a conditional "set to empty string" operator (the string equivalent of the torx): $x x=!! $y is same as $x = '' unless $y; $x x=! $y -- $x = '' if $y;
    These screwdriver operators follow on from earlier secret operator work, such as Dmitry Karasik's original set of "!"-based secret operators and BooK's flaming X-wing operator (@data{@fields} =<>=~ $re).

    March 2012 Update: BooK at it again, this time proposing a new sperm secret operator. An alternative name is the "kite" secret operator.

    From perlsecret:

    Perl secret operators:

    Operator Nickname Function ================================================ 0+ Venus numification @{[ ]} Babycart list interpolation !! Bang bang boolean conversion }{ Eskimo greeting END block for one-liners ~~ Inchworm scalar ~- Inchworm on a stick high-precedence decrement -~ Inchworm on a stick high-precedence increment -+- Space station high-precedence numification =( )= Goatse aka Saturn scalar / list context =< >=~ Flaming X-Wing match input and assign captures ~~<> Sperm <<m=~>> m ; Ornate double-bladed sword -=! -=!! Flathead +=! +=!! Phillips x=! x=!! Pozidriv *=! *=!! Torx
    Update: for the inchwormy operators above, see also the "Inchworm" and "Inchworm on a stick" sections at perlsecret and The Lighter Side of Perl Culture (Part IV): Golf (search for inchworm).

    Perl secret constants:

    Constant Nickname Value ================================================= <=><=><=> Space fleet 0 <~> Amphisbaena $ENV{HOME}

    See also BooK proposes a new Perl secret operator.

    October 2014 Update: Re: Perl Idioms Explained - ${\$obj->method} and @{[sort @list]} by ambrus proposes a new "twin baby cart" operator, as used by tybalt89 and tails in winning golf entry at shinh's golf site:

    /[3-9]/||print"@{[world,hello,'world!']}[/./g] "for 0..$$

      I believe that @{[]} is known as the "baby buggy". Can't remember where I read that though.

        Originally, a crude name was proposed for this operator, as indicated by this response from BooK to Sebastien Aperghis-Tramoni:

        > Hey Philippe, why don't you give the name we found for @{[]} ?

        Because *you* found it, and want to have *my* name associated with it.

        To deflect attention from the taboo name, BooK started another fwp thread, suggesting "Baby Cart" ... which was objected to by native English speakers on the grounds they'd never heard it used in everyday speech. Suggested alternatives included "Baby Carriage" and "Pram". Though many other names have been proposed, including:

        it seems that BooK's quirky Baby Cart has won this fascinating naming war.

        References Added Later

      Tadpole secret operator ~~($$..!$$) can be used as a kind of counter
      print $_ , ' => ', ~~($$..!$$), "\n" for qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
Re: Hidden features of Perl
by Arunbear (Prior) on Jun 22, 2009 at 10:12 UTC
Re: Hidden features of Perl
by Anonymous Monk on Jun 22, 2009 at 02:28 UTC
    Hidden? I don't think there are any left hiding :)
Re: Hidden features of Perl
by Jenda (Abbot) on Jun 22, 2009 at 13:24 UTC

    Esoteric? What the heck is esoteric about them? Agrrr. Anything that's not apparent to someone with strictly imperative background with no computer science knowledge whatsoever is deemed "esoteric". Nonsense.

    Enoch was right!
    Enjoy the last years of Rome.

      W(hat|TF) does this have to do with "imperative" or "computer science?" It seems non-obvious to me that a magic filehandle called "DATA" reads everything in the current file after a line containing only "__DATA__". Perl has a lot of non-obvious features, and that thread lists quite a few of them.

        It seems that you are arguing semantics, which isn't the point of this post.. post whatever _you_, personally, consider a "hidden feature". Don't worry about what others consider esoteric. :)

        Most of the stuff is something that looks esoteric to someone who was taught C or Fortran or who taught him/her-self VB and is so used to imperative programming, that he/she cannot think outside that old tiny box. The people that find references hard and higher order functions rocket science.

        And the DATA filehandle is no more esoteric than a print statement. A bit unusual maybe, non-obvious probably, but esoteric? That's a very big stretch of the meaning of the word.

        Enoch was right!
        Enjoy the last years of Rome.

Re: Hidden features of Perl
by whakka (Hermit) on Jun 22, 2009 at 23:23 UTC
    Not so much a "hidden feature" but a shout-out to Inline::C for making the task of hooking C code to Perl criminally easy. I would include all examples in the Cookbook to be good examples of "hidden" features, particularly the prospect of object-oriented C with Perl5 API calls.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://773443]
Approved by ysth
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2022-01-18 13:03 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (53 votes). Check out past polls.