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

Re: "Secret" operators

Thread Previous | Thread Next
From:
José Castro
Date:
February 2, 2005 02:22
Subject:
Re: "Secret" operators
Message ID:
20050202102242.GB8808@natura.di.uminho.pt
* McGlinchy, Alistair (Alistair.McGlinchy@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.
--
Jose Alves de Castro <cog@cpan.org>
      http://jose-castro.org/

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