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

RE: "Secret" operators

Thread Previous | Thread Next
McGlinchy, Alistair
February 1, 2005 13:03
RE: "Secret" operators
Message ID:
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.

	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   ==
	print (0+'20GBP') x 3;  # Wrong. x 3 is applied to the return of
	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. :-)



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


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

Registered No. 214436 in England and Wales.

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


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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About