Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Wrong idioms

by educated_foo (Vicar)
on Mar 30, 2013 at 02:40 UTC ( [id://1026226]=note: print w/replies, xml ) Need Help??


in reply to Wrong idioms

Why shouldn't I have a file named "0"?
Just as a side note... Regardless of correctness, "don't name your files with obnoxious names" is good advice if you want to avoid problems with others' software. "0" is kind of a corner case, but if you stick to alphanumerics, '-', and '_', you're less likely to have to fix other people's stuff. On the one hand, you're "technically correct" using all sorts of filenames. On the other hand, you're just asking for trouble.

Replies are listed 'Best First'.
Re^2: Wrong idioms
by vsespb (Chaplain) on Mar 30, 2013 at 09:39 UTC
    Hm, I think '-' can cause problems with getopts sometimes. Also - what other languages treat '0' as false?

      "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
      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)

      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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-19 11:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found