Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Thoughts on some new operators for perl (6 or 7)

by etcshadow (Priest)
on Mar 10, 2004 at 07:02 UTC ( #335375=note: print w/ replies, xml ) Need Help??


in reply to Thoughts on some new operators for perl (6 or 7)

Really, the operator that I want is ''= or some such. This would be the equivalent of ||=, but for comparison against eq '' rather than boolean true-falseness.

I understand that there is a patch out there for a //= operator that does the same thing for undef, and I think that's really cool... but I'd still like to see the empty-string defaulting operator, as well.

------------ :Wq Not an editor command: Wq


Comment on Re: Thoughts on some new operators for perl (6 or 7)
Select or Download Code
Re: Re: Thoughts on some new operators for perl (6 or 7)
by Juerd (Abbot) on Mar 10, 2004 at 08:10 UTC

    I'd guess it's not useful enough for the core language, but I might be guessing wrong. However, should it not be implemented, then with Perl 6 you can still choose to do so yourself:

    sub infix:'' ($foo, $bar) { $foo eq '' ? $bar : $foo } sub infix:''= ($foo is rw, $bar) { $foo = $foo '' $bar }
    Likewise, the OP can implement their new operators if they really want it.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      The '//' and '//=' (defined or) operators aren't in the core because they tend to be ambigious with an empty regex (like in split //, $str). They should be in 5.10, though.

      ----
      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

        The '//' and '//=' (defined or) operators aren't in the core because they tend to be ambigious with an empty regex (like in split //, $str). They should be in 5.10, though.

        Ehm, I have no idea what you're responding to, but I do think your example isn't a very good one. The comma in split //, $foo would disambiguate. Perl knows when to expect a value and when to expect an operator (I'm sure you've seen those "... found where ... expected" syntax errors).

        Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://335375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-07-11 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (224 votes), past polls