Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Hidden features of Perl (More Secret Operator References)

by eyepopslikeamosquito (Archbishop)
on Jun 22, 2009 at 23:44 UTC ( #773791=note: print w/replies, xml ) Need Help??


in reply to Hidden features of Perl

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 (http://en.wikipedia.org/wiki/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).

Jan 2010 Update: LanX created a "poll" (really a meditation) at Poll: How should the =( )= be called??? in an attempt to solve the well-known naming issues of this idiom: =( )=. Though Rolex narrowly defeated Saturn back then, nowadays LanX prefers wristwatch.

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}

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..$$

See also: BooK proposes a new Perl secret operator (Secret Operator References) and Perl Secret Operator Emojis (2023)

Replies are listed 'Best First'.
Re^2: Hidden features of Perl
by ambrus (Abbot) on Jun 23, 2009 at 17:06 UTC
Re^2: Hidden features of Perl
by cdarke (Prior) on Jun 29, 2009 at 11:06 UTC
    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.

      BooK References

      Quoting BooK from Interview with Philippe Bruhat (August 2015):

      I've been hanging around on the Fun with Perl mailing for a long time, and this is where Josť Castro started to ask for the names of the most famous secret operators for his OGSOP (Obfuscation, Golfing and Secret Operators in Perl) book project. I came up with the name "baby cart" for @{[]}, and I loved that name so much that I wanted to make sure it would be the one that everyone would use. The only way to do that was to write the reference manual myself...

      Early Historical References

      References Added Later

      Comparing Baby Cart with String Interpolation in Other Languages (Golf)

      Though usually too long for golf, Baby Cart occasionally features in competitive golf solutions, as you will discover by searching for Baby Cart in the following nodes:

      Based on these nodes, consider how to create a "Dear John" string in each of the four languages:

      "Dear $name" # Perl and PHP "Dear %s" % expr # Python and Ruby % printf-like operator "Dear {0}".format(expr) # Python format string method "Dear "+`expr` # Python backticks (TMTOWTDI) "Dear #{expr}" # Ruby string interpolation "Dear @{[expr]}" # Perl "Baby Cart" string interpolation "Dear {expr}" # Perl 6 version of Baby Cart (I think)

      My 102 stroke Perl solution to the Saving Time challenge used Baby Cart to create a printf format string on the fly:

      printf"%@{[.1*vec'XXXXXXXXXXXX',$_,8]}s",($_^$`%12?g:p)&($_^$'/5?g:u)| +"H "for map{$_,11-$_}<>!~/:/..5

      What's the shortest way to create this peculiar printf format string from an expression (expr) in each of the four languages?

      TechniquePerlRubyPythonPHP
      String interpolate"%@{[expr]}s""%#{expr}s""%%%ds"%expr~X.expr.s
      Number of strokes1311129

      where X above is the character with ord value 218. Poor old Baby Cart baby-stepped to the finish line in last place in this oddball race. This is hardly surprising given Baby Cart was not really designed; it was independently "invented" shortly after Perl 5 was released in 1994 by both L.Wall and R.Schwartz ... and later celebrated as one of Perl's secret operators.

      Updated: Many changes were made and extra references added long after the original response was made.

Re^2: Hidden features of Perl
by ccn (Vicar) on Aug 10, 2009 at 19:14 UTC
    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);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://773791]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2023-12-06 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (30 votes). Check out past polls.

    Notices?