Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Secret" operators

26 views
Skip to first unread message

José Castro

unread,
Feb 1, 2005, 6:49:57 AM2/1/05
to f...@perl.org
Hi, guys.

Apart from the "secret eskimo greeting" and the "goatse operator", can
anyone tell me about other "secret" operators?

Examples:

eskimo: }{
goatse: =()=

eskimo usage: perl -ne '}{print $.'
goatse usage: perl -e '$_="zbrughau";$b=()=/u/g;print $b'

TIA,

jac

--
Jose Alves de Castro <c...@cpan.org>
http://jose-castro.org/

Philippe 'BooK' Bruhat

unread,
Feb 1, 2005, 9:57:33 AM2/1/05
to f...@perl.org
Le mardi 01 février 2005 à 11:49, José Castro écrivait:

> Hi, guys.
>
> Apart from the "secret eskimo greeting" and the "goatse operator", can
> anyone tell me about other "secret" operators?
>
> Examples:
>
> eskimo: }{
> goatse: =()=
>
> eskimo usage: perl -ne '}{print $.'
> goatse usage: perl -e '$_="zbrughau";$b=()=/u/g;print $b'

There's also @{[]} but I don't know f it has a name.

Usage: print "splatt @{[ ... ]} pow"
where ... is any valid expression, and the result list is join()ed with $"
(space).

--
Philippe "BooK" Bruhat

There are two sides to every cause. Do not join one until you know the other.
(Moral from Groo The Wanderer #105 (Epic))

Philippe 'BooK' Bruhat

unread,
Feb 1, 2005, 10:06:37 AM2/1/05
to f...@perl.org
Le mardi 01 février 2005 à 11:49, José Castro écrivait:
> Hi, guys.
>
> Apart from the "secret eskimo greeting" and the "goatse operator", can
> anyone tell me about other "secret" operators?
>
> Examples:
>
> eskimo: }{
> goatse: =()=
>
> eskimo usage: perl -ne '}{print $.'
> goatse usage: perl -e '$_="zbrughau";$b=()=/u/g;print $b'
>

There's also the golf version of scalar(): ~~

Usage: perl -e 'print~~gmtime'

I'd call it the "spit" operator (based on my understanding of the :P~
smiley), but maybe it already has a name.

--
Philippe "BooK" Bruhat

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

Vladi Belperchinov-Shabanski

unread,
Feb 1, 2005, 11:57:47 AM2/1/05
to f...@perl.org
On Tue, 1 Feb 2005 15:57:33 +0100
philipp...@free.fr (Philippe 'BooK' Bruhat) wrote:

>
> There's also @{[]} but I don't know f it has a name.
>
> Usage: print "splatt @{[ ... ]} pow"
> where ... is any valid expression, and the result list is join()ed with $"
> (space).

[] construct reference to anonymous array, @{} dereferences the array ref.
finally the array is interpolated inside string.

it is equal to:

@a = ( 1, 2, 3 );
print "splatt @a pow";

the only use is to force array context inside string:

%a = ( 1, 2, 3 );
print "splatt @{[%a]} pow";

but don't think it is usefull (except obfuscation bonus:))

--
Vladi Belperchinov-Shabanski <ca...@biscom.net> <ca...@datamax.bg>
Personal home page at http://cade.datamax.bg/
DataMax SA http://www.datamax.bg
there is still one truth on which we can depend
we've started something we can never end

Philippe 'BooK' Bruhat

unread,
Feb 1, 2005, 12:12:53 PM2/1/05
to f...@perl.org
Le mardi 01 février 2005 à 18:57, Vladi Belperchinov-Shabanski écrivait:

> On Tue, 1 Feb 2005 15:57:33 +0100
> philipp...@free.fr (Philippe 'BooK' Bruhat) wrote:
>
> >
> > There's also @{[]} but I don't know f it has a name.
> >
> > Usage: print "splatt @{[ ... ]} pow"
> > where ... is any valid expression, and the result list is join()ed with $"
> > (space).
>
> [] construct reference to anonymous array, @{} dereferences the array ref.
> finally the array is interpolated inside string.
>
> it is equal to:
>
> @a = ( 1, 2, 3 );
> print "splatt @a pow";
>
> the only use is to force array context inside string:
>
> %a = ( 1, 2, 3 );
> print "splatt @{[%a]} pow";
>
> but don't think it is usefull (except obfuscation bonus:))

I won't defend its usefulness (we're here for fun), but sometimes you
don't want to type

use Acme::MetaSyntactic 'batman';
print "splatt " . join( " ", metaname(3) ) . " pow";

when

use Acme::MetaSyntactic 'batman';
print "splatt @{[metaname 3]} pow";

will do.

--
Philippe "BooK" Bruhat

A reputation is only as good as the truth beneath it, if any.
(Moral from Groo The Wanderer #91 (Epic))

Andy Bach

unread,
Feb 1, 2005, 12:15:46 PM2/1/05
to Vladi Belperchinov-Shabanski, f...@perl.org
Can I get that just a little slower?

$b = () = /u/g;

is the same as:

@a = /u/g;
$b = @a;

I understand what happens, but it appears to be assigning to an empty list
- is that filling up the list, so to speak? Or is it just that it makes
the 'result' of /u/g assign in array/list context and then that, assigned
in scalar context to $b gives the list/array count.

I tried to explain this once and I had to resort to 'and then <mumble
mumble> and in scalar context, we get the count of the elements in $b!'

a

Andy Bach, Sys. Mangler
Internet: andy...@wiwb.uscourts.gov
VOICE: (608) 261-5738 FAX 264-5932

"Bugs happen. A bug is a test case you haven't written yet."
Mark Pilgrim

Ronald J Kimball

unread,
Feb 1, 2005, 12:36:46 PM2/1/05
to Andy...@wiwb.uscourts.gov, Vladi Belperchinov-Shabanski, f...@perl.org
On Tue, Feb 01, 2005 at 11:15:46AM -0600, Andy...@wiwb.uscourts.gov wrote:
> Can I get that just a little slower?
>
> $b = () = /u/g;
>
> is the same as:
>
> @a = /u/g;
> $b = @a;
>
> I understand what happens, but it appears to be assigning to an empty list
> - is that filling up the list, so to speak? Or is it just that it makes
> the 'result' of /u/g assign in array/list context and then that, assigned
> in scalar context to $b gives the list/array count.

It is assigning to an empty list. A list assignment in scalar context
returns the number of elements on the right-hand side of the assignment.


You can assign two elements to a two-element list:

($foo, $bar) = (1, 2);

You can assign two elements to a one-element list:

($foo) = (1, 2);

You can even assign two elements to an empty list:

() = (1, 2);


In each case, any extra elements are simply discarded, but the result of
the assignment in scalar context is always the number of elements on the
right-hand side, even if some aren't actually assigned to variables.


Ronald

Vladi Belperchinov-Shabanski

unread,
Feb 1, 2005, 12:11:05 PM2/1/05
to f...@perl.org
On Tue, 1 Feb 2005 11:49:57 +0000
Jos_ Castro <j...@natura.di.uminho.pt> wrote:

> Hi, guys.
>
> Apart from the "secret eskimo greeting" and the "goatse operator", can
> anyone tell me about other "secret" operators?
>
> Examples:
>
> eskimo: }{
> goatse: =()=
>
> eskimo usage: perl -ne '}{print $.'

perl -MO=Deparse -ne 'print $.'

has this actual code:

LINE: while (defined($_ = <ARGV>)) {
print $.;
}

on the other hand your example:


perl -MO=Deparse -ne '}{print $.'

actually is:


LINE: while (defined($_ = <ARGV>)) {
();
}
{
print $.;
}

the trick is that you can have loop and finish code:

perl ' loop-code-here }{ finish-code-here'

> goatse usage: perl -e '$_="zbrughau";$b=()=/u/g;print $b'

$b = () = /u/g;

is the same as:

@a = /u/g;
$b = @a;

i.e. () forces array context (actually it is array), then returns element count in $b

no big secrets here, though I never thought of such () use. thanks for the hint :))

José Castro

unread,
Feb 1, 2005, 12:40:38 PM2/1/05
to f...@perl.org
* Ronald J Kimball (rjk-pe...@tamias.net) wrote:
> You can assign two elements to a one-element list:
>
> ($foo) = (1, 2);
>
> You can even assign two elements to an empty list:
>
> () = (1, 2);
>
>
> In each case, any extra elements are simply discarded, but the result of
> the assignment in scalar context is always the number of elements on the
> right-hand side, even if some aren't actually assigned to variables.

Which is why this:

perl -e '$_ = ($foo) = (1, 2) ; print'

prints out 2.

Georg Moritz

unread,
Feb 1, 2005, 12:25:01 PM2/1/05
to Andy...@wiwb.uscourts.gov, Vladi Belperchinov-Shabanski, f...@perl.org
From the keyboard of Andy...@wiwb.uscourts.gov [01.02.05,11:15]:

> Can I get that just a little slower?
>
> $b = () = /u/g;
>
> is the same as:
>
> @a = /u/g;
> $b = @a;

it's not the same.

perl -le '$_="foo"; print $b =()= /o/g'
2
perl -le '$_="foo"; print @b =()= /o/g'

perl -le '$_="foo"; print /o/g'
oo

The brackets in =()= means something like 'here would have been n elements,
were you interested'. There's no list, only list context.

-gg-

> I understand what happens, but it appears to be assigning to an empty list
> - is that filling up the list, so to speak? Or is it just that it makes
> the 'result' of /u/g assign in array/list context and then that, assigned
> in scalar context to $b gives the list/array count.
>
> I tried to explain this once and I had to resort to 'and then <mumble
> mumble> and in scalar context, we get the count of the elements in $b!'
>
> a
>
> Andy Bach, Sys. Mangler
> Internet: andy...@wiwb.uscourts.gov
> VOICE: (608) 261-5738 FAX 264-5932
>
> "Bugs happen. A bug is a test case you haven't written yet."
> Mark Pilgrim
>

--
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s,/,($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e,e && print}

Philippe 'BooK' Bruhat

unread,
Feb 1, 2005, 12:52:10 PM2/1/05
to f...@perl.org
Le mardi 01 février 2005 à 17:40, José Castro écrivait:

> * Ronald J Kimball (rjk-pe...@tamias.net) wrote:
> > You can assign two elements to a one-element list:
> >
> > ($foo) = (1, 2);
> >
> > You can even assign two elements to an empty list:
> >
> > () = (1, 2);
> >
> >
> > In each case, any extra elements are simply discarded, but the result of
> > the assignment in scalar context is always the number of elements on the
> > right-hand side, even if some aren't actually assigned to variables.
>
> Which is why this:
>
> perl -e '$_ = ($foo) = (1, 2) ; print'
>
> prints out 2.

I think a better example is :

$ perl -e '$_ = ($foo) = (1,3); print'
2

versus

$ perl -e '$_ = $foo = (1,3); print'
3

There you can see how () was useful, and be reminded that a list in
scalar context returns its last element.

--
Philippe "BooK" Bruhat

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

José Castro

unread,
Feb 1, 2005, 1:10:57 PM2/1/05
to Jeff Yoak, José Castro, f...@perl.org
* Jeff Yoak (je...@yoak.com) wrote:
> > eskimo usage: perl -ne '}{print $.'
>
> This is wonderfully deranged. I haven't seen it before, but it was
> immediately clear what it does.

>
> > goatse usage: perl -e '$_="zbrughau";$b=()=/u/g;print $b'
>
> This is probably even more wonderfully deranged as it *isn't* clear what
> it does, even after running it. Can you explain this one? And also,
> what does the name "goatse" mean?

You had to ask about the name, didn't you? :-)

See the explanation here: http://perlmonks.org/?node_id=426037

You can follow this link safely (it's a perlmonks node), but a word of
caution: in that thread, a guy explains the origin of the name, and
provides another link... for the love of god, *do not* follow that
link!!! :-)

Regards,

Bernie Cosell

unread,
Feb 1, 2005, 1:20:21 PM2/1/05
to f...@perl.org
On 1 Feb 2005 at 12:36, Ronald J Kimball wrote:

> ... A list assignment in scalar context


> returns the number of elements on the right-hand side of the assignment.

Which is an odd inconsistency, because in list context a list assignment
returns the left-hand-side-list, so you might guess that in scalar
context it'd return the number of elements in the lhs list...

/Bernie\

--
Bernie Cosell Fantasy Farm Fibers
mailto:ber...@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--

Quantum Mechanic

unread,
Feb 1, 2005, 2:55:00 PM2/1/05
to f...@perl.org

--- Bernie Cosell <ber...@fantasyfarm.com> wrote:

> On 1 Feb 2005 at 12:36, Ronald J Kimball wrote:
>
> > ... A list assignment in scalar context
> > returns the number of elements on the right-hand
> side of the assignment.
>
> Which is an odd inconsistency, because in list
> context a list assignment
> returns the left-hand-side-list, so you might guess
> that in scalar
> context it'd return the number of elements in the
> lhs list...

It seems there are multiple contexts flying around.
I'm no expert, but it seems to develop this way:

$foo = $bar = (9,8,7);

RHS list
$bar scalar
$bar <- 7 (last element of list)
$foo <- 7

$foo = ($bar) = (9,8,7);

RHS list
($bar) array
$bar <- 7 (rest discarded)
$foo <- 3, size of RHS of ($bar) assignment

Therefore,

$foo = () = (9,8,7)

RHS list
() array
no assignment targets, but...
$foo <- 3, size of RHS of () assignment

My assumption is that =()= creates an intermediate
assignment, which subtley shifts the context so that
$foo gets the count of (9,8,7) in the last case,
instead of the last element of (9,8,7) as in the first
case.

=()= forks the assigment flow. The elements of the
right operand are assigned (if possible) to the
contained array, as in

$foo = ($bar) = (9,8,7);
or
$foo = @bar = (9,8,7);

The left operand of =()= is assigned the element count
of the other assignment.

Someone familiar with the core will have to clue me in
on the accuracy of my theory.

-QM


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quantum Mechanics: The dreams stuff is made of



__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com

José Castro

unread,
Feb 1, 2005, 2:59:28 PM2/1/05
to Quantum Mechanic, f...@perl.org
* Quantum Mechanic (quantum_me...@yahoo.com) wrote:
> $foo = ($bar) = (9,8,7);
>
> RHS list
> ($bar) array
> $bar <- 7 (rest discarded)

No, no, no.

$bar <- 9

It's the same as

$foo = ($bar, undef, undef) = (9, 8, 7);

Now the funny thing is that the result from

$foo = ($bar, undef, undef, undef) = (9, 8, 7);

is still the same :-)

Quantum Mechanic

unread,
Feb 1, 2005, 3:12:51 PM2/1/05
to José, f...@perl.org

--- José Castro <j...@natura.di.uminho.pt> wrote:

> * Quantum Mechanic (quantum_me...@yahoo.com)
> wrote:
> > $foo = ($bar) = (9,8,7);
> >
> > RHS list
> > ($bar) array
> > $bar <- 7 (rest discarded)
>
> No, no, no.
>
> $bar <- 9
>

Yes, that was a typo -- thanks.

> It's the same as
>
> $foo = ($bar, undef, undef) = (9, 8, 7);
>
> Now the funny thing is that the result from
>
> $foo = ($bar, undef, undef, undef) = (9, 8, 7);
>
> is still the same :-)

Ah, but that supports my theory. It's not the LHS of
the ($bar,...)= assignment that generates the data for
$foo -- it's the RHS. The LHS of the ($bar,...)=
assignment determines the *context* of the $foo=
assignment.

Q.E.D. The quantity of elements on the LHS don't
matter, but the quality of the LHS does.

-QM

=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quantum Mechanics: The dreams stuff is made of



__________________________________
Do you Yahoo!?
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250

Alistair McGlinchy

unread,
Feb 1, 2005, 4:02:56 PM2/1/05
to f...@perl.org
Hi All,

High in fun, but low in usefulness is -+- , a high precedence string
numerifier. It sort of looks like an A C Clarke style spacestation so
that's what I've been calling it. Although I'm not too sure that Larry's
spaceship <=> would be able to dock to easily.

Examples:
print -+-'23a' # prints 23
print -+-'3.00' # prints 3
print -+-'1.2e3' # prints 1200

I know 0+ does the trick too, but binary + has a relatively low
precedence. Perl will automatically numerify the arguments of the *
operator but won't do so for x, !~ or =~. Hence this operator is useful
for removing unsightly parenthesises from some expressions.

print 0+'20GBP' x 3; # Wrong. Prints 20 ==
0+"20GBP20GBP20GBP"
print (0+'20GBP') x 3; # Wrong. x 3 is applied to the return of
print
print((0+'20GBP') x 3); # Right, but too Lispy
print -+-'20GBP' x 3; # Right. Spacestation to the rescue!

Unfortunately -+- is bugged [*], but I'll leave these as gotcha's for
your production code. :-)

Cheers,

Alistair

[*] You might want to consider: print -+- '-2B' x 5; # Bug?


-----------------------------------------------------------------------

==================================================
Registered Office:
Marks and Spencer plc
Waterside House
35 North Wharf Road
London
W2 1NW

Registered No. 214436 in England and Wales.

Telephone (020) 7935 4422
Facsimile (020) 7487 2670

<<www.marksandspencer.com>>

Please note that electronic mail may be monitored.

This e-mail is confidential. If you received it by mistake, please let us know and then delete it from your system; you should not copy, disclose, or distribute its contents to anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.

Yitzchak Scott-Thoennes

unread,
Feb 1, 2005, 4:48:33 PM2/1/05
to Bernie Cosell, f...@perl.org
On Tue, Feb 01, 2005 at 01:20:21PM -0500, Bernie Cosell wrote:
> On 1 Feb 2005 at 12:36, Ronald J Kimball wrote:
>
> > ... A list assignment in scalar context
> > returns the number of elements on the right-hand side of the assignment.
>
> Which is an odd inconsistency, because in list context a list assignment
> returns the left-hand-side-list, so you might guess that in scalar
> context it'd return the number of elements in the lhs list...

But the lhs usually either has a fixed number of elements or includes
arrays/hashes so the number of elements is arbitrarily large. Using
the rhs allows common idioms like:

while (my ($k, $v) = each %hash) {
}

Here list-context each returns 2 elements (a key/value pair) until the
hash is exhausted, whereupon it returns 0 elements, terminating the loop.

Andrew Savige

unread,
Feb 1, 2005, 8:33:35 PM2/1/05
to José Castro, f...@perl.org
José Castro wrote:
> Apart from the "secret eskimo greeting" and the "goatse operator",
> can anyone tell me about other "secret" operators?

Let's not forget the Ton Hospel "high-precedence decrement"
operator ~- invented during a golf tournament (anyone remember
which one?).

IIRC, Ton's ~- invention allows you to eliminate the parens in:

$y = ($x-1)*4;

by using instead:

$y = ~-$x*4;

saving a whopping two strokes. This trick should work on any
twos complement machine -- and I'm not aware of any perl running
on any non twos complement machine.

/-\


Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com

Quantum Mechanic

unread,
Feb 1, 2005, 11:56:55 PM2/1/05
to f...@perl.org
--- Andrew Savige <ajsa...@yahoo.com.au> wrote:
>
> Let's not forget the Ton Hospel "high-precedence
> decrement"
> operator ~- invented during a golf tournament
> (anyone remember
> which one?).
>

What did he call it?

I'd suggest the "inchworm", because in some fonts, it
resembles an inchworm on a stick.

Philippe 'BooK' Bruhat

unread,
Feb 2, 2005, 12:58:30 AM2/2/05
to f...@perl.org
Le mardi 01 février 2005 à 20:56, Quantum Mechanic écrivait:

> --- Andrew Savige <ajsa...@yahoo.com.au> wrote:
> >
> > Let's not forget the Ton Hospel "high-precedence
> > decrement"
> > operator ~- invented during a golf tournament
> > (anyone remember
> > which one?).
> >
>
> What did he call it?
>
> I'd suggest the "inchworm", because in some fonts, it
> resembles an inchworm on a stick.

So we have :

symbol nickname Role
------ -------- ----
<=> spaceship documented operator

0+ venus numification
}{ eskimo greeting END{} in one-liners
=()= goatse
~- inchworm on a stick high-precedence numification
~~ inchworm scalar
"@{[]}" join $", ...
-+- spacestation high-precedence numification

Not bad for a start.

--
Philippe "BooK" Bruhat

Everyone acts their age... mental, if not physical.
(Moral from Groo The Wanderer #92 (Epic))

Andrew Savige

unread,
Feb 2, 2005, 1:25:52 AM2/2/05
to Philippe 'BooK' Bruhat, f...@perl.org
Not that it is seen very often, but you might try dreaming up a
name for:

]->[

I first saw this operator employed in a graceful way to return the
lesser of $x and $y:

[ $x => $y ]->[ $y <= $x ]

Andrew Savige

unread,
Feb 2, 2005, 2:44:17 AM2/2/05
to Philippe 'BooK' Bruhat, f...@perl.org
Philippe 'BooK' Bruhat wrote:
> So we have :
>
> symbol nickname Role
> ------ -------- ----
> <=> spaceship documented operator
>
> 0+ venus numification
> }{ eskimo greeting END{} in one-liners
> =()= goatse
> ~- inchworm on a stick high-precedence numification
> ~~ inchworm scalar
> "@{[]}" join $", ...
> -+- spacestation high-precedence numification

For the sake of the Perl historians, it would be nice to properly
attribute these inventions.

The table below is based on wild guesswork. If there are any oldbies
listening, please chime in with corrections.

Secret Operator Inventor Year
--------------- -------- ----

@{[]} aka ??? The Schwartz early 1990s
}{ aka eskimo greeting The Abigail late 1990s
=()= aka goatse ???
-+- aka spacestation The McGlinchy ???
~~ aka inchworm ???
~- aka inchworm-on-a-stick The Hospel 2002

We could also classify golfing techniques:

Golfing Technique Inventor Year
----------------- -------- ----

$_ x= boolean expression The Larry early 1990s
y///c aka Abigail's Length Horror The Abigail late 1990s
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
-i and $^I for data value The Sperling 2002

Notice that some of the secret operators above also double as
golfing techniques. I'm sure there are plenty of other golfing
techniques I've forgotten because I am so rusty.

Eric Krohn

unread,
Feb 1, 2005, 9:44:18 PM2/1/05
to f...@perl.org

Andrew Savige wrote:
> twos complement machine -- and I'm not aware of any perl running
> on any non twos complement machine.

I ported Perl 1.0 (and probably 2.0) to UNIX 1100 (UNIX as guest OS on
Univac 1100). The machine was 36-bit, ones complement, word addressable.
Porting software to this beast was often a challenge. Fortunately, I
haven't had to use that hardware in a long, long time (~1989)!

--
Eric Krohn

José Castro

unread,
Feb 2, 2005, 5:17:40 AM2/2/05
to f...@perl.org
* Andrew Savige (ajsa...@yahoo.com.au) wrote:
> Not that it is seen very often, but you might try dreaming up a
> name for:
>
> ]->[
>
> I first saw this operator employed in a graceful way to return the
> lesser of $x and $y:

Or the greater, if used like this:

[ $x => $y ]->[ $x <= $y ]

or

[ $x => $y ]->[ $y >= $x ]

> [ $x => $y ]->[ $y <= $x ]
>
> /-\
>
>
> Find local movie times and trailers on Yahoo! Movies.
> http://au.movies.yahoo.com

José Castro

unread,
Feb 2, 2005, 5:22:42 AM2/2/05
to f...@perl.org
* McGlinchy, Alistair (Alistair....@marks-and-spencer.com) wrote:
> Hi All,
>
> High in fun, but low in usefulness is -+- , a high precedence string
> numerifier. It sort of looks like an A C Clarke style spacestation so
> that's what I've been calling it. Although I'm not too sure that Larry's
> spaceship <=3D> would be able to dock to easily.

Of course it would!

<=>
|
+
|

Larry's probably been there a couple of times...

> Examples:
> print -+-'23a' # prints 23

> print -+-'3.00' # prints 3=09


> print -+-'1.2e3' # prints 1200

> =09


> I know 0+ does the trick too, but binary + has a relatively low
> precedence. Perl will automatically numerify the arguments of the *

> operator but won't do so for x, !~ or =3D~. Hence this operator is =


> useful
> for removing unsightly parenthesises from some expressions.
>

> print 0+'20GBP' x 3; # Wrong. Prints 20 =3D=3D


> 0+"20GBP20GBP20GBP"
> print (0+'20GBP') x 3; # Wrong. x 3 is applied to the return of
> print

> print((0+'20GBP') x 3); # Right, but too Lispy=20


> print -+-'20GBP' x 3; # Right. Spacestation to the rescue!
>
> Unfortunately -+- is bugged [*], but I'll leave these as gotcha's for
> your production code. :-)
>
>
>
> Cheers,
>
> Alistair
>
> [*] You might want to consider: print -+- '-2B' x 5; # Bug?
>
>
> -----------------------------------------------------------------------
>

> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
> =3D=3D


> Registered Office:
> Marks and Spencer plc
> Waterside House
> 35 North Wharf Road
> London
> W2 1NW
>
> Registered No. 214436 in England and Wales.
>
> Telephone (020) 7935 4422

> =46acsimile (020) 7487 2670


>
> <<www.marksandspencer.com>>
>
> Please note that electronic mail may be monitored.
>

> This e-mail is confidential. If you received it by mistake, please =
> let us know and then delete it from your system; you should not =
> copy, disclose, or distribute its contents to anyone nor act in =


> reliance on this e-mail, as this is prohibited and may be unlawful.

Vladi Belperchinov-Shabanski

unread,
Feb 2, 2005, 9:20:05 AM2/2/05
to f...@perl.org
On Wed, 2 Feb 2005 12:33:35 +1100 (EST)
Andrew Savige <ajsa...@yahoo.com.au> wrote:

> Jos_ Castro wrote:
> > Apart from the "secret eskimo greeting" and the "goatse operator",
> > can anyone tell me about other "secret" operators?
>
> Let's not forget the Ton Hospel "high-precedence decrement"
> operator ~- invented during a golf tournament (anyone remember
> which one?).
>
> IIRC, Ton's ~- invention allows you to eliminate the parens in:
>
> $y = ($x-1)*4;
>
> by using instead:
>
> $y = ~-$x*4;
>
> saving a whopping two strokes. This trick should work on any
> twos complement machine -- and I'm not aware of any perl running
> on any non twos complement machine.

will not work if $x < 0

>
> /-\
>
>
> Find local movie times and trailers on Yahoo! Movies.
> http://au.movies.yahoo.com
>

Sébastien Aperghis-Tramoni

unread,
Feb 2, 2005, 3:36:46 PM2/2/05
to Philippe 'BooK' Bruhat, f...@perl.org
Philippe 'BooK' Bruhat wrote:

> So we have :
>
> symbol nickname Role
> ------ -------- ----
> <=> spaceship documented operator
>
> 0+ venus numification
> }{ eskimo greeting END{} in one-liners
> =()= goatse
> ~- inchworm on a stick high-precedence numification
> ~~ inchworm scalar
> "@{[]}" join $", ...
> -+- spacestation high-precedence numification
>
> Not bad for a start.

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


Sébastien Aperghis-Tramoni
-- - --- -- - -- - --- -- - --- -- - --[ http://maddingue.org ]
Close the world, txEn eht nepO

Quantum Mechanic

unread,
Feb 2, 2005, 4:19:04 PM2/2/05
to f...@perl.org

--- Philippe 'BooK' Bruhat <philipp...@free.fr>
wrote:

>
> symbol nickname Role
> ------ -------- ----
> <=> spaceship documented
> operator
>
> 0+ venus numification
> }{ eskimo greeting END{} in
> one-liners
> =()= goatse
> ~- inchworm on a stick
> high-precedence numification
> ~~ inchworm scalar
> "@{[]}" join $", ...
> -+- spacestation
> high-precedence numification
>

Other naming suggestions:

~- inchworm
or cotton candy (on a stick)
~~ caterpillar
"@{[]}" cyclops (one eye with eyebrows,
mustache, and square mouth)
-+- cross-hair (or half cross-hair)
or vanishing point (horizon line)
or reticule
]->[ Frowning Sam (resembles the Muppet
named Sam the Eagle)
Beaker (the nerdish Muppet with the
perpetual surprised look)


=====
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quantum Mechanics: The dreams stuff is made of



__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com

Bart Lateur

unread,
Feb 2, 2005, 7:21:52 PM2/2/05
to f...@perl.org
On Tue, 1 Feb 2005 11:49:57 +0000, José Castro wrote:can

>anyone tell me about other "secret" operators?

I just produced this in my own code, I think it would qualify. Take this
expression in list context:

cond ? foo : ()

I'm talking about the 3 characters at the end: ": ()". I'd call it a
"frogs face".

--
Bart.

Chris Dolan

unread,
Feb 2, 2005, 3:58:28 PM2/2/05
to Sébastien Aperghis-Tramoni, Fun With Perl
On Feb 2, 2005, at 2:36 PM, Sébastien Aperghis-Tramoni wrote:

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

It looks like a guy lying on his side in a straightjacket to me.

Chris
--
Chris Dolan, Software Developer, www.chrisdolan.net
Public key: http://www.chrisdolan.net/public.key

PGP.sig

Eugene van der Pijll

unread,
Feb 2, 2005, 5:54:07 PM2/2/05
to f...@perl.org
Andrew Savige schreef:

> The table below is based on wild guesswork. If there are any oldbies
> listening, please chime in with corrections.

Not an oldbie, but...

> @{[]} aka ??? The Schwartz early 1990s

The Larry, May 1 1994
http://groups-beta.google.com/group/comp.lang.perl/msg/1d82c7c3f3e94266

> y///c aka Abigail's Length Horror The Abigail late 1990s

Although I agree about the name, the inventor seems to have been The
Hall, Jun 22 1996
http://groups-beta.google.com/group/comp.lang.perl.misc/msg/7680c5d579b5fc23

> stuff value into $\ for printing The van der Pijll 2001

I'm almost sure that I've seen a very early post by Larry, Randal, or
Tom Christiansen (most probably Larry), where this trick is used. I did
come up with it independently, though.

gr,Eu

Philippe 'BooK' Bruhat

unread,
Feb 3, 2005, 5:30:18 AM2/3/05
to Sébastien Aperghis-Tramoni, f...@perl.org
Le mercredi 02 février 2005 à 21:36, Sébastien Aperghis-Tramoni écrivait:

> Philippe 'BooK' Bruhat wrote:
>
> >So we have :
> >
> > symbol nickname Role
> > ------ -------- ----
> > <=> spaceship documented operator
> >
> > 0+ venus numification
> > }{ eskimo greeting END{} in one-liners
> > =()= goatse
> > ~- inchworm on a stick high-precedence numification
> > ~~ inchworm scalar
> > "@{[]}" join $", ...
> > -+- spacestation high-precedence numification
> >
> >Not bad for a start.
>
> 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.

--
Philippe "BooK" Bruhat

All life affects us... even that which is far from our gaze.
(Moral from Groo The Wanderer #59 (Epic))

Peter Haworth

unread,
Feb 3, 2005, 6:45:13 AM2/3/05
to f...@perl.org
On Wed, 2 Feb 2005 16:20:05 +0200, Vladi Belperchinov-Shabanski wrote:
> On Wed, 2 Feb 2005 12:33:35 +1100 (EST)
> > IIRC, Ton's ~- invention allows you to eliminate the parens in:
> >
> > $y = ($x-1)*4;
> >
> > by using instead:
> >
> > $y = ~-$x*4;
> >
> > saving a whopping two strokes. This trick should work on any twos
> > complement machine -- and I'm not aware of any perl running on any
> > non twos complement machine.
>
> will not work if $x < 0

It does if you C<use integer>, but that's no good for golf, (unless
you need 6 decrements, of course).

Incidentally, -~$x will increment negative numbers, but fails on >=0
for the same reason.

--
Peter Haworth p...@edison.ioppublishing.com
"Ah, you're only calling [perl threads] experimental because it's slow,
broken in spots, and has problems with backwards compatibility. What kind
of labelling is that? (And where does it leave Windows NT?)"
-- Dan Sugalski

Randal L. Schwartz

unread,
Feb 3, 2005, 6:15:17 AM2/3/05
to f...@perl.org
>>>>> "Eugene" == Eugene van der Pijll <vande...@gmail.com> writes:

>> @{[]} aka ??? The Schwartz early 1990s

Eugene> The Larry, May 1 1994
Eugene> http://groups-beta.google.com/group/comp.lang.perl/msg/1d82c7c3f3e94266

The array version was actually discussed in private email between me
and Larry, if I recall correctly, shortly before that public post,
because I had come up with it for some courseware of mine.

But, this *is* 10 years ago, and I could be mismembering.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Yitzchak Scott-Thoennes

unread,
Feb 3, 2005, 3:07:39 PM2/3/05
to Vladi Belperchinov-Shabanski, f...@perl.org
On Wed, Feb 02, 2005 at 04:20:05PM +0200, Vladi Belperchinov-Shabanski wrote:
> On Wed, 2 Feb 2005 12:33:35 +1100 (EST)
> Andrew Savige <ajsa...@yahoo.com.au> wrote:
>
> > Jos_ Castro wrote:
> > > Apart from the "secret eskimo greeting" and the "goatse operator",
> > > can anyone tell me about other "secret" operators?
> >
> > Let's not forget the Ton Hospel "high-precedence decrement"
> > operator ~- invented during a golf tournament (anyone remember
> > which one?).
> >
> > IIRC, Ton's ~- invention allows you to eliminate the parens in:
> >
> > $y = ($x-1)*4;
> >
> > by using instead:
> >
> > $y = ~-$x*4;
> >
> > saving a whopping two strokes. This trick should work on any
> > twos complement machine -- and I'm not aware of any perl running
> > on any non twos complement machine.
>
> will not work if $x < 0

Except under "use integer". A little known fact is that perl's bitops
cast operands to unsigned integers without "use integer" and to signed
integers with "use integer".

Yitzchak Scott-Thoennes

unread,
Feb 3, 2005, 3:07:31 PM2/3/05
to McGlinchy, Alistair, f...@perl.org
On Tue, Feb 01, 2005 at 09:02:56PM -0000, McGlinchy, Alistair wrote:
> Unfortunately -+- is bugged [*], but I'll leave these as gotcha's for
> your production code. :-)
>
> [*] You might want to consider: print -+- '-2B' x 5; # Bug?

No. perlop say: if the string starts with a plus or minus, a string
starting with the opposite sign is returned.

Alistair McGlinchy

unread,
Feb 4, 2005, 5:39:09 AM2/4/05
to Yitzchak Scott-Thoennes, f...@perl.org

Hmmm. Looks like I didn't put enough smilies there. Perhaps the much
more bugged^?^?^?^?^?^? robust reciprocal operator /// will put your
mind at rest. :-)

print ///4; # prints 0.25 :-)

Cheers, :-)

Alistair


**********************************************************************


Registered Office:
Marks and Spencer plc
Waterside House
35 North Wharf Road
London
W2 1NW

Registered No. 214436 in England and Wales.

Telephone (020) 7935 4422
Facsimile (020) 7487 2670

<<www.marksandspencer.com>>

Please note that electronic mail may be monitored.

This e-mail is confidential. If you received it by mistake, please let us know and then delete it from your system; you should not copy, disclose, or distribute its contents to anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.


Rafael Garcia-Suarez

unread,
Feb 4, 2005, 3:54:23 AM2/4/05
to f...@perl.org
José Castro wrote in perl.fwp :

>
> Apart from the "secret eskimo greeting" and the "goatse operator", can
> anyone tell me about other "secret" operators?

I think nobody mentioned the toothpick operator yet.

/\/\//

Exists also in extra-large version.

--
Tsk tsk, that's not an O'Reilly title. You must be thinking of "Fucking
Everything Up With XML", "XML Nightmares: The Definitive Guide", or
"Hell & XML".
-- Nathan Torkington, http://use.perl.org/comments.pl?cid=7404&sid=4864

Yanick Champoux

unread,
Feb 4, 2005, 9:42:33 AM2/4/05
to Andrew Savige, Philippe 'BooK' Bruhat, f...@perl.org
Andrew Savige wrote:

>> "@{[]}" join $", ...
>>
>>

My better half proposes to call this one the papoose operator.


Joy,
`/anick

Philippe 'BooK' Bruhat

unread,
Feb 4, 2005, 6:45:18 PM2/4/05
to Yanick Champoux, Andrew Savige, f...@perl.org
Le vendredi 04 février 2005 à 09:42, Yanick Champoux écrivait:

> Andrew Savige wrote:
>
> >> "@{[]}" join $", ...
> >>
> >>
> My better half proposes to call this one the papoose operator.

Or the trolley operator (as in supermarkets), where you stuff everything
you want to take out.

--
Philippe "BooK" Bruhat

Ignorance weaves a web from which none can escape.
(Moral from Groo The Wanderer #52 (Epic))

0 new messages