Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: how to enable, disable strict

by shmem (Chancellor)
on Apr 25, 2007 at 08:41 UTC ( [id://611939] : note . print w/replies, xml ) Need Help??


in reply to how to enable, disable strict

You've got it right in that strict is enabled with use strict and disabled with no strict - but:
It is an error to put anything but whitespace between the if block and the elsif keyword. Maybe you want
use strict; while(1) { print "please enter a guess from 1 to 100: "; chomp(my $guess = <STDIN>); if ($guess =~ /quit|exit|^s*$/i) { print " sorry you gave up.the number was $secret.\n"; last; } elsif ($guess < $secret) { no strict; print "you failed \n"; } }

- but why?

Just leave it enabled. In normal coding you always want to have it; in fact, there are only few situations where some strictness must be disabled, such as hacking perl internals. As the strict documentation states, it is a "pragma to restrict unsafe constructs" - and it is always better to be on the safe side.

BTW, had you indented your code properly, you would have seen that you missed the last right curly... ;)

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: how to enable, disable strict
by elsiddik (Scribe) on Apr 25, 2007 at 09:05 UTC
    Oh i missed that -- now its working thanx alot mate, and `bout the last curly guess i missed it when i typed the script in here and added <#BR#> for the html script :-)