Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Why use strict is good, and barewords are bad

by Booger (Pilgrim)
on Apr 21, 2005 at 18:12 UTC ( #450135=note: print w/ replies, xml ) Need Help??


in reply to Why use strict is good, and barewords are bad

The @months array fails to properly store the barewords because...

 oct is a reserved word that is interprets $_ as an octal scring returns a corresponding value

But this would have worked...
@months = (jan,feb,mar,apr,may,jun,jul,aug,sep,'oct',nov,dec);
Heh.


Comment on Re: Why use strict is good, and barewords are bad
Select or Download Code
Re^2: Why use strict is good, and barewords are bad
by hardburn (Abbot) on Apr 21, 2005 at 19:10 UTC

    Until a new reserved word is added to the language. I could see dec used as a decrement operation equivilent to $foo = $bar - 1;. Or maybe you have a module that imports an apr() sub into your namespace for calculating Annual Precentage Rates. Or maybe something completely different.

    The point is, you can't guarentee that any of those won't take a different meaning at some point in the future, so you should just avoid using them as barewords.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

      LOL:). One more to my colllection of "expect the unexpected".

      My 1st guess out of jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec
      was "may",
      second - "dec",
      and only 3d - "oct"
      (note that I don't Perl).

      Imagine:
      may $foo == $bar; then $awk = sep($foo, $bar, 18) unless oct(18) eq int("2".dec("2.00000 +0)")

      :-).
      Or maybe you have a module that imports an apr() sub into your namespace for calculating Annual Precentage Rates.
      As long as subs (or new buildins) without arguments return a string with the same name as they have, all will be well. I mean, if oct were to be defined that oct() eq "oct", the OPs example would not have been a problem.

        While I like the clever solution to the problem at hand (barewords), I'm much happier that Perl chose the DWIMery of using a default argument of $_, e.g.: perl -Mstrict -lwe 'print for map oct, qw/077 777 034/'

        (63, 511, 28) vs. ("oct", "oct", "oct")

        And if we could get around those pesky laws of thermodynamics, we could have a perpetual motion machine.

        "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-07-30 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (237 votes), past polls