Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Wrong idioms

by vsespb (Chaplain)
on Mar 30, 2013 at 09:39 UTC ( [id://1026260]=note: print w/replies, xml ) Need Help??


in reply to Re: Wrong idioms
in thread Wrong idioms

Hm, I think '-' can cause problems with getopts sometimes. Also - what other languages treat '0' as false?

Replies are listed 'Best First'.
Re^3: Wrong idioms
by tobyink (Canon) on Mar 30, 2013 at 21:16 UTC

    "Also - what other languages treat '0' as false?"

    It would be horrible if "0" were treated as true, given that the integer 0 is false and Perl silently converts between strings and numbers.

    What other languages? PHP does.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re^3: Wrong idioms
by LanX (Saint) on Mar 31, 2013 at 00:33 UTC
    Update: Post recomposed for better readability

    > Also - what other languages treat "0" as false?

  • JavaScript

    Num yes Str no

    >>> !! 0 false >>> !! "0" true

  • Python

    Num yes Str no

    >>> not not 0 False >>> not not "0" True

  • Ruby

    Num no Str no

    irb(main):002:0> !! 0 => true irb(main):003:0> !! "0" (irb):3: warning: string literal in condition => true

  • Perl

    Num yes Str yes

    DB<102> !! 0 => "" DB<103> !! "0" => ""

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^3: Wrong idioms
by educated_foo (Vicar) on Mar 31, 2013 at 20:00 UTC
    Hm, I think '-' can cause problems with getopts sometimes.
    Oops! Starting filenames with '-' is just asking for trouble. Your life will be least painful if you start names with [a-z_], use only one '.', don't make them too long, and don't rely on case differences alone. If you find yourself wanting arbitrary filenames, either never pass them to other software, or consider using a database.
      I remember a colleague who used to create files named "-i" in directories he wanted to protect. That way, when you did "rm *", the file list expanded into "rm -i ..." and you got prompted for each file. I'm not recommending it, but he liked it.

        The first thing I do when given a new shell account is alias rm to rm -i to protect everyone from me. :P

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-19 11:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found