develooper Front page | perl.fwp | Postings from February 2005

RE: "Secret" operators

Thread Previous | Thread Next
From:
McGlinchy, Alistair
Date:
February 1, 2005 13:03
Subject:
RE: "Secret" operators
Message ID:
8B653E54B22CC741B9D5AF5FD15126FC0118E77D@MSHVSMNSEXP0002.mnsexchange.adroot.marksandspencer.com
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.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About