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

(jeffa) Re: Poor Perl Idioms Explained (except not really)

by jeffa (Bishop)
on Aug 02, 2003 at 14:12 UTC ( [id://280280]=note: print w/replies, xml ) Need Help??


in reply to Re: Poor Perl Idioms Explained (except not really)
in thread Perl Idioms Explained - $|++

An old manager of mine saw $|++ in some of my code and requested i change it to $| = 1. I asked why and he replied that it's better to explicitly set something than to assume it is, say, zero. I know that $| defaults to 0, you know that $| defaults to 0 ... but what if someday the default for $| is instead 1?

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on (jeffa) Re: Poor Perl Idioms Explained (except not really)

Replies are listed 'Best First'.
Re^2: Poor Perl Idioms Explained (except not really)
by robin (Chaplain) on Oct 26, 2005 at 17:00 UTC
    what if someday the default for $| is instead 1?
    That's not the problem:
    $ perl -le '$| = 1; $|++; print $|++' 1
    The problem is that it might confuse someone who doesn't know about this particular piece of DWIMmery.

    Update: removed unfunny joke

      Even more obvious:
      $ perl -le '$| = 42; print $|;$|--;print $|' 1 0
      So $|++ always sets it to true, and $|-- toggles it. Useful to know, but not obvious, and not consistent. But then DWIMmery is not necessarily consistent.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

      I can tell you didn't actually test this.

      Actually, i did test it. But you try telling contrary to a manager that won't listen to you. ;) Even if you show him such code. And no ... i don't work for him anymore. :)

      Anyways, the point was not what it is now, but what will it be if it changed sometime in the future.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-25 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found