Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Barewords equal zero?

by rgiskard (Hermit)
on Feb 12, 2008 at 18:54 UTC ( #667648=note: print w/ replies, xml ) Need Help??


in reply to Barewords equal zero?

An example for the lazy folks out there, that demonstrates (for beginners) why warnings would be useful in addition to strict.

using strict only
use strict; my $string = 'hello world'; print substr($string,'O',5)."\n";
Output doesn't really scream don't use the letter O:
perl absurd.pl hello
using strict and warnings
use strict; use warnings; my $string = 'hello world'; print substr($string,'O',5)."\n";
Useful output with some notes on what should be a number and isn't:
perl absurd.pl Argument "O" isn't numeric in substr at absurd.pl line 4. hello


Comment on Re: Barewords equal zero?
Select or Download Code
Re^2: Barewords equal zero?
by ikegami (Pope) on Feb 12, 2008 at 21:12 UTC

    I noticed you changes the OP's code to something that strict wouldn't catch...

    But you're right.
    strict will catch some things.
    warnings will catch others.
    Both have their uses.

      In the previous example, I put quotes around the capital letter O. Because, quite frankly, barewords are painful.

      It's also important to look at it from the perspective of someone fixing the barewords but not fixing the real problem, as some may read the capital letter O and think it to be a zero (0) and brute force the solution by getting rid of the barewords by quoting everything.

      So without warnings, there's no difference between a quoted letter O and a quoted number 0. If one is starting out with the language then hopefully I've pointed out some positives about strict and warning.

      example with a quoted number zero
      use strict; use warnings; my $string = 'hello world'; print substr($string,'0',5)."\n";
      output
      sh-3.2$ perl absurd2.pl hello

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-09-20 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls