Re: Secret operators: the documentation

2012-04-03 Thread Philippe Bruhat (BooK)
On Mon, Apr 02, 2012 at 06:28:56PM +0200, Alexis Sukrieh wrote:
 Le 16 mars 2012 12:44, Philippe Bruhat (BooK)
 philippe.bru...@free.fr a écrit :
  So,
 
  A few years back, I started to write a manual page about Perl secret 
  operators,
  with the goal of getting it into the official Perl documentation at some 
  point.
 [...]
  Patches welcome.
 
  When it's stabilized enough, I'll send a patch to p5p.
 
 Nice work :)
 
 I have a question though;
 
 Did you change your mind about the A word of warning section? It
 sounds that it won't fit well in the official Perl documentation ;)
 

I've pushed a branch on the Perl source tree, and Abigail already
patched the module a bit.
http://perl5.git.perl.org/perl.git/shortlog/refs/heads/book/perlsecret

The word of warning still holds. The page is specifically not listed
in the main perl.pod manual page. The idea is to hide it a little, so that
people who know about it can easily point inquiring minds to it, while not
making these official.

I also wrote a test script (t/japh/secret.t) and it helped a lot in refining
exactly how and when each of those worked.

-- 
 Philippe Bruhat (BooK)

 Did I err?  (Groo, in too many issues to count - ...and *YES* he did!)


Re: Secret operators: the documentation

2012-04-03 Thread Philippe Bruhat (BooK)
On Tue, Apr 03, 2012 at 03:43:54AM -0700, Andrew Savige wrote:
 
 
 I wonder if --$| and $|--, very popular in golf, and described
 by japhy as the magical flip flop variable at:
 
  http://www.nntp.perl.org/group/perl.fwp/2002/01/msg1367.html
 
 qualifies as a secret operator?
 

I have had several requests for adding more obscure constructs (see
https://github.com/book/perlsecret/issues). My rule has been to keep
only the well-known operators, or the ones that had a nickname that
corresponded to their looks, not their function.

Under that rulle, the magical flip-flop wouldn't have fit.

Anyway, I guess others can decide what gets in when the branch merged
into blead.

-- 
 Philippe Bruhat (BooK)

 Out of the worst can often come the best.
(Moral from Groo The Wanderer #57 (Epic))


Re: The sperm secret operator: is it new?

2012-03-16 Thread Philippe Bruhat (BooK)
On Thu, Mar 15, 2012 at 10:40:17AM +0100, Dmitry Karasik wrote:
 
  Does that mean I have a dirty mind?
 
 At least not dirtier than the inventor of the =()= (unless that was you ;)

I think the first person using =()= (Randal?) is not the same as
the first person naming it in a Perl context. Both probably have been
invented independently, as goatse was a popular meme at some point, and
people collected references to it. It's not suprising that a minimalist
ascii-art version appeared. And that it looked like Perl code.

-- 
 Philippe Bruhat (BooK)

 The man who most obeys the king is the man who gets crowned.
(Moral from Groo The Wanderer #13 (Epic))


Secret operators: the documentation

2012-03-16 Thread Philippe Bruhat (BooK)
So,

A few years back, I started to write a manual page about Perl secret operators,
with the goal of getting it into the official Perl documentation at some point.

Somehow I got interested in that again, and started to really work on it.
The current work in progress is availabled at: 
https://github.com/book/perlsecret

I've already included most of the feedback from the discussions on ~~.

Patches welcome.

When it's stabilized enough, I'll send a patch to p5p.

-- 
 Philippe Bruhat (BooK)

 Too many believe only in the belief.
(Moral from Groo The Wanderer #58 (Epic))


Re: The sperm secret operator: is it new?

2012-03-15 Thread Philippe Bruhat (BooK)
On Thu, Mar 15, 2012 at 06:25:49AM +0100, Dmitry Karasik wrote:
  
  While doing some tests/research on secret operators, I stumbled upon this
  one in my one-liners:
  
  ~~
  
  Obviously, this should be named the sperm operator. 
 
 
 Looks more like a kite operator to me.
 

Does that mean I have a dirty mind?

-- 
 Philippe Bruhat (BooK)

 Law is the best deterrent to Justice.
(Moral from Groo The Wanderer #90 (Epic))


Re: The sperm secret operator: is it new?

2012-03-15 Thread Philippe Bruhat (BooK)
On Thu, Mar 15, 2012 at 03:45:47PM +0100, Dmitry Karasik wrote:
  ~~
  Looks more like a kite operator to me.
  Does that mean I have a dirty mind?
 
 That means that there's no such thing as a four-squared sperm! 
 

Not that =()= resembles much to a... Hrmpf.

See also http://en.wikipedia.org/wiki/Sperm.
The side view is four-squared enough for me.

The limitations of ASCII shouldn't limit our imaginations!

-- 
 Philippe Bruhat (BooK)

 Too many believe only in the belief.
(Moral from Groo The Wanderer #58 (Epic))


The sperm secret operator: is it new?

2012-03-14 Thread Philippe Bruhat (BooK)
Hi,

While doing some tests/research on secret operators, I stumbled upon this
one in my one-liners:

~~

Obviously, this should be named the sperm operator. It's only useful
in list context. Just like sperm cells work better when there are many
of them. ;-)


Now, if you want to get a number from that line you just read, you
could use this variation:

~~+0

which we could name the fertilisation, conception, fecundation or
syngamy operator, except the flagella (~~) has become useless, since
the +0 operator (ovum?) already provides scalar context. So it's just
the same as +0.

I have no idea if this operator is really new, or if someone else found
and named it already before today. My Google-fu is too weak to make
useful searches on it.

-- 
 Philippe Bruhat (BooK)

 No matter who you may be, there is always someone who is a little worse
 because he thinks he is a little better.
 (Moral from Groo The Wanderer #3 (Epic))


Re: The sperm secret operator: is it new?

2012-03-14 Thread Philippe Bruhat (BooK)
On Wed, Mar 14, 2012 at 12:36:10PM +0100, Philippe Bruhat (BooK) wrote:
 Hi,
 
 While doing some tests/research on secret operators, I stumbled upon this
 one in my one-liners:
 
 ~~
 
 Obviously, this should be named the sperm operator. It's only useful
 in list context. Just like sperm cells work better when there are many
 of them. ;-)
 

Example usage:

   # the first three lines constitute the header
   @header = ( ~~, ~~, ~~ );

-- 
 Philippe Bruhat (BooK)

 The only way to get a better government is to get better voters.
   (Moral from Groo The Wanderer #109 (Epic))


Re: The sperm secret operator: is it new?

2012-03-14 Thread Philippe Bruhat (BooK)
On Wed, Mar 14, 2012 at 01:46:34PM -0700, Andrew Savige wrote:
  [ ~~ vs. scalar ]
 
 The ~~ secret operator is old hat, good ol' inchworm:
 
  http://www.catonmat.net/blog/secret-perl-operators/#inchworm
 
 BooK's innovation is to add  and +0 to the end of it.
 
 BTW, in addition to inchworm-on-a-stick ~- to subtract one,
 I often use the converse -~ to add one (though only in Ruby
 and Python, not usually Perl). For example, -~1 produces 2
 in Ruby and Python, but -4,294,967,294 in Perl.
 

It works in C too. I was doing some research on secret operators today,
and I discovered the effects of the other inchworm-on-a-stick, and the
fact that both operators are broken for half the integers in Perl.

~- only decrements integers greater than 0 in Perl.
-~ only increments integers lesser than 0 in Perl.

According to Abigail and rgs, it's probably because ~ must also handle
strings. Abigail and I looked at the source of pp_negate, and it seems
like it does the right thing, so ~ seems to be the culprit. (I see that
tzchak Scott-Thoennes has provided a thorough answer in another mail.)

Frankly, I think this could be considered a bug. Both the left-facing
and right-facing versions of the inchworm on a stick should work on
all integers in Perl. Complement two arithmetics demand it! Now, the
question is, how long has this been broken in Perl? Forever?

-- 
 Philippe Bruhat (BooK)

 The learned man makes a mistake but once... but the truly stupid keep
 practicing until they get it right.
(Moral from Groo The Wanderer #75 (Epic))


Re: Rate my JAPH

2011-11-14 Thread Philippe Bruhat (BooK)
On Mon, Nov 14, 2011 at 01:50:25PM +0100, Salve J Nilsen wrote:

 If it helps, pretend to be a pretentious Art critic that is paid to
 give a positive review of some crappy modern painting.

 Get creative! My signature Art needs attention! ;D


I would give a positive review of your crappy modern coding,
but I'm not paid for it. ;-)

-- 
 Philippe Bruhat (BooK)

 Solve a problem before you become part of it.
(Moral from Groo The Wanderer #60 (Epic))


Re: Rate my JAPH

2011-11-11 Thread Philippe Bruhat (BooK)
On Thu, Nov 10, 2011 at 03:14:22PM +0100, Salve J Nilsen wrote:
 
 Wow, nice to se something happening on this list. :)
 
 Would anyone like to rate my old JAPH below? (Don't know how to rate
 it, but maybe it can be fun to figure that out... ;)
 

Rating JAPH seems very difficult. One could rate asbtract things like 
creativity, beauty, or give bonus points for not using sigils, or eval,
or malus points for using modules.

Oh well, it can't be more difficult than rating art. Only maybe just as
difficult. ;-)

-- 
 Philippe Bruhat (BooK)

 Did I err?  (Groo, in too many issues to count - ...and *YES* he did!)


Re: Just to say hello

2011-11-09 Thread Philippe Bruhat (BooK)
On Wed, Nov 09, 2011 at 06:02:54PM +0100, Sandro CAZZANIGA wrote:

 I'm new to this list and I'll send some JAPH's and little code, and I
 will happy to read yours. :)


Well, the latest mail I received on this list was from Fri, 4 Sep 2009
16:38:22 -0500, so you might need a little patience if you want to read
some code. Better write it!

-- 
 Philippe Bruhat (BooK)

 Where there are hearts of gold, there is no need for bars of steel.
   (Moral from Groo The Wanderer #103 (Epic))


Re: Another one-liner?

2009-06-24 Thread Philippe Bruhat (BooK)
On Wed, Jun 24, 2009 at 04:26:05PM +0100, Jasper wrote:
 2009/6/24 Daniel Tiefnig dan...@gmx.at:
 
   perl -00 -ne'/.{65535}/||print'
 
 
 of course becomes
 
 perl -00 -pe'$_ x=!/.{65535}/'
 

Did you notice that this (x=!) is a secret operator of the same family
as the screwdriver operators discovered by Dmitry Karasik and showed
some time ago (November 2007) on fwp.

Actually, Dmitry only showed three of them:

 This bunch, I think, can be appropriately named screwdriver operators:
 
-=! and -=!!- flathead
+=! and +=!!- phillips
*=! and *=!!- torx

When preparing my talk on the Perl secret operators for the last French
Perl Workshop (and hopelessly looking for nice pictures of screwdrivers),
I realized that, in real life, there are several types or cruciform
(or cross-head) screwdrivers. It had to be the same in Perl!

Ladies and gentlemen, it is my pleasure to introduce you to the fourth
screwdriver operator, the Pozidriv (http://en.wikipedia.org/wiki/Pozidriv):

   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;


I hope you'll welcome it in your toolbox, like Jasper did.

-- 
 Philippe Bruhat (BooK)

 The fish most likely to be caught is the one with the biggest mouth.
(Moral from Groo The Wanderer #17 (Epic))


Re: YN golf

2008-04-01 Thread Philippe Bruhat (BooK)
On Mon, Mar 31, 2008 at 11:37:05PM -0500, Chris Dolan wrote:
 On Mar 31, 2008, at 6:54 PM, Philippe Bruhat (BooK) wrote:
 On Mon, Mar 31, 2008 at 04:34:58PM -0700, Rick Klement wrote:

 perl -le 'print for glob{Y,N}x5'


 Of course you have to run this in a directory that doesn't contain
 any file matching /^[YN]{5}$/.

 Not true.  The {} notation doesn't care whether files of that name  
 actual exist.  I tested like so on Mac:

I was pretty sure I tried the same manipulation to obtain all permutations
of some series of strings, and that it didn't work as expected when one of
the permutations actually existed as a file in the current directory.

After a quick check, you are right and I was too. :-)
What I tried was:

$ touch Y
$ perl -le 'print for glob[YN]x5'
Y

I computed my permutations with square brackets (which is one character
shorter, but more fragile).

-- 
 Philippe Bruhat (BooK)

 To flaunt your strength is to make it your weakness.
(Moral from Groo The Wanderer #25 (Epic))


Re: YN golf

2008-03-31 Thread Philippe Bruhat (BooK)
On Mon, Mar 31, 2008 at 04:34:58PM -0700, Rick Klement wrote:
 
 perl -le 'print for glob{Y,N}x5'
 

Of course you have to run this in a directory that doesn't contain
any file matching /^[YN]{5}$/.

-- 
 Philippe Bruhat (BooK)

 The learned man makes a mistake but once... but the truly stupid keep
 practicing until they get it right.
(Moral from Groo The Wanderer #75 (Epic))


Name the secret operator

2008-03-19 Thread Philippe Bruhat (BooK)
Hi,

while doing some research for a talk on Perl secret operators, I tried
to find who first coined the term secret operator.

I found a post from Greg Allen on February 2004 on this very list
(http://groups.google.com/group/perl.fwp/msg/e62668a760de1652),
and then a post by Abigail on comp.lang.perl.misc on January 2003
(http://groups.google.com/group/comp.lang.perl.misc/msg/22cfcd81a1521ec4).

Does anyone know of an earlier occurence of the term?


Now that I have seen Abigail's post on clpm, I want to know its name.
It is the longest secret operator I've seen, and also the only one
that must be on three lines (not counting the content).

m=~m 
  (commented out code and pod goes here)
m
;

I have a few ideas for names, but they don't fit very well, and do not
describe the m\n; part of the operator. 

-- 
 Philippe Bruhat (BooK)

 Putting beauty before brains is the surest way to wind up with neither.
(Moral from Groo The Wanderer #24 (Epic))


Re: The flaming X-wing secret operator

2007-11-30 Thread Philippe Bruhat (BooK)
On Fri, Nov 30, 2007 at 09:43:36AM +0100, Philippe Bruhat (BooK) wrote:
 
  Me likes. Lots.  I propose, as alternative names for those two tokens, 
  the 
  fat bat (because it does look like a particularly rotund specimen of that 
  species, and in honor of the large value it yields) and thelaughing joker 
  (as in, just kidding, the rest of the line doesn't apply). :-)
 
 Of course, we now need canonical usage examples of those two.
 

One usage could combine them two. When you need to use the largest
possible integer on 32 bits, you can use them both. Of course, it's a
slight golf (1 character winned), but a real golfer will do much better.

2**32-1  # UINT_MAX
[EMAIL PROTECTED]@^   # fat bat  laughing joker
~0   # golf hole

-- 
 Philippe Bruhat (BooK)

 The right answer is worthless with the wrong question!
(Moral from Groo The Wanderer #88 (Epic))


Re: The flaming X-wing secret operator

2007-11-30 Thread Philippe Bruhat (BooK)
On Thu, Nov 29, 2007 at 08:01:45PM -0500, Yanick Champoux wrote:
 shmem wrote:
 To brighten up your day - here's the winged moon, which isn't an
 operator, but a constant:

 [EMAIL PROTECTED]

 Georg added:
 Similar to the winged moon - an operator (token?) which scares
 the hell out of the remainder of a list:

 [EMAIL PROTECTED]


   Me likes. Lots.  I propose, as alternative names for those two tokens, 
 the 
 fat bat (because it does look like a particularly rotund specimen of that 
 species, and in honor of the large value it yields) and thelaughing joker 
 (as in, just kidding, the rest of the line doesn't apply). :-)

Of course, we now need canonical usage examples of those two.

-- 
 Philippe Bruhat (BooK)

 Blood is thicker than water... so beware of thick relatives.
(Moral from Groo The Wanderer #18 (Epic))


Re: The flaming X-wing secret operator

2007-11-29 Thread Philippe Bruhat (BooK)
On Thu, Nov 29, 2007 at 09:54:25AM +0100, Philippe Bruhat (BooK) wrote:
 
 # DATA is the pilot, for the sake of the example
 @[EMAIL PROTECTED] =DATA=~ $re;
 

Did I just inadvertently make a Star Wars/Star Trek cross-over?

-- 
 Philippe Bruhat (BooK)

 He who revels in being bigger forgets that he is the larger target.
 (Moral from Groo #5 (Image))


Re: The flaming X-wing secret operator

2007-11-29 Thread Philippe Bruhat (BooK)
On Wed, Nov 28, 2007 at 05:09:57PM -0500, Mr. Shawn H. Corey wrote:
 Philippe Bruhat (BooK) wrote:
 Hi,

 Just thought I should share this with the FWP crowd.

 I had to do something special with the first line of a file, before
 running the whole while() loop on it. I ended up with this:

 @[EMAIL PROTECTED] ==~ $re;

 Rafael helped me give this new operator a name (#perlfr transcript):

 15:13 @BooK OMG c'est quoi ==~ comme secret op ?
 15:14 @rgs le x-wing touché avec une aile en feu

 Rough translation:

 15:13 @BooK OMG what is ==~ for a secret op ?
 15:14 @rgs the hit x-wing starfighter with a wing on fire

 Cog, are you still writing this OGSOP book? ;-)


 Actually, it's:

  @[EMAIL PROTECTED] = (  =~ $re );


Actually, it's not:

use strict;
use warnings;
use Data::Dumper;

my @fields = qw( H M S );
my $re = qr/(\d\d):(\d\d):(\d\d)/;
my %data;

# DATA is the pilot, for the sake of the example
@[EMAIL PROTECTED] =DATA=~ $re;

print Dumper \%data;

__DATA__
the time is now 03:14:15

Which outputs:

$VAR1 = {
  'H' = '03',
  'M' = '14',
  'S' = '15'
};

Why would I need parentheses, when the hash slice gives me a list
context already?

-- 
 Philippe Bruhat (BooK)

 For every winner, there must be one or more losers.
(Moral to the Sage story in Groo #111 (Epic))


Re: The flaming X-wing secret operator

2007-11-29 Thread Philippe Bruhat (BooK)
On Thu, Nov 29, 2007 at 01:09:20PM +0100, Dmitry Karasik wrote:
 
  Philippe @[EMAIL PROTECTED] ==~ $re;
 
 That gives me a reason to pick symmetrical names for my filehandles in the 
 future:
 
  =W=~
  =O__O=~
  =IX000H000XI=~
 
 that'll be an X-wing squadron :)
 

Or you could go down the fan fic way, and imagine the Empire is about
to win, now that the Red Squadron is severily hit:

 =Biggs_Darklighter=~
 =Jek_Porkins=~
 =Wedge_Antilles=~
 =Luke_Skywalker=~

-- 
 Philippe Bruhat (BooK)

 In war, the only winners are those who sell the weapons.
 (Moral from Groo #3 (Image))


Re: The flaming X-wing secret operator

2007-11-29 Thread Philippe Bruhat (BooK)
On Thu, Nov 29, 2007 at 09:20:20AM -0500, Mr. Shawn H. Corey wrote:
 Philippe Bruhat (BooK) wrote:
 Why would I need parentheses, when the hash slice gives me a list
 context already?


 The parentheses, like the whitespace, are for clarification; to make
 it easier to understand what is happening.

Clarification is off-topic when you wander in the realm of golfing and
secret operators.

 Also, it is not one operator, it is three.

I don't think you fully understand what secret operators are, then. :-)

For some background on secret operators, you can read the following
thread in the archives:

http://groups.google.com/group/perl.fwp/browse_thread/thread/4416004e60b67101

-- 
 Philippe Bruhat (BooK)

 To flaunt your strength is to make it your weakness.
(Moral from Groo The Wanderer #25 (Epic))


The flaming X-wing secret operator

2007-11-28 Thread Philippe Bruhat (BooK)
Hi,

Just thought I should share this with the FWP crowd.

I had to do something special with the first line of a file, before
running the whole while() loop on it. I ended up with this:

@[EMAIL PROTECTED] ==~ $re;

Rafael helped me give this new operator a name (#perlfr transcript):

15:13 @BooK OMG c'est quoi ==~ comme secret op ?
15:14 @rgs le x-wing touché avec une aile en feu

Rough translation:

15:13 @BooK OMG what is ==~ for a secret op ?
15:14 @rgs the hit x-wing starfighter with a wing on fire

Cog, are you still writing this OGSOP book? ;-)

-- 
 Philippe Bruhat (BooK)

 No matter how many times you explain the big problem, some people see only
 their small problem.
   (Moral to the Sage story, in Groo The Wanderer #93 (Epic))