CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
use strict;



Feb 23, 2001, 1:31 AM

Post #1 of 5 (542 views)
use strict; Can't Post

My script worked just fine, then I tried to use strict; and I got errors for nearly every variable...

Global symbol "$quantity" requires explicit package name at searchstock.cgi line 83.

What does this mean?
Could this cause problems??
Or will I be okay if I simply don't use strict........... (it seems to be working fine)

emelin - the newbie with the stupidest q's :)


Feb 23, 2001, 2:29 PM

Post #2 of 5 (535 views)
Re: use strict; [In reply to] Can't Post

strict puts an environment on your script that requires you to declare all of your variables. You can do this by either

A - Declaring them with my ($variable); or local ($variable). The difference is that my will keep the variable to just that subroutine, while local will make it availble to any other subroutine called during the proccess of the subroutine it's declared in.

B - If you need your variable to be global, at the top the script you can insert use vars qw($variable1 $variable2);. You can also put arrays and hashs in this. In scripts that I use that have a parser, i declare the entire hash that the input gets stored in as global, which is simpler than doing this use vars qw($input{'name'} $input{'email'} $input{'icq'} ...);. And because there is qw before the (), you don't have to include any commas between the variables.

Jeffrey "muinatit" Lamoureux

User / Moderator

Feb 23, 2001, 5:41 PM

Post #3 of 5 (532 views)
Re: use strict; [In reply to] Can't Post

When you use strict, perl will try to keep you from doing stupid things. So if your script is longer than a page you probably should have a very good reason if you do not turn it on.

The most obvious example of what you get with strict is that if you misspell a variable name, it will not be declared and you will get the error message.

There are good reasons to sometimes not use strict, like if you are doing wizardly things that strict does not like. But in that case you are doing dangerous things, you know you are doing dangerous things, and you are willing to live with the risks. And even then, you can 'use strict' for most of the code and then do a 'no strict' to turn it off where needed.

For more on declaring variables with my, local, use vars, and our look at this post from the past.

Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


Feb 24, 2001, 6:07 AM

Post #4 of 5 (527 views)
Re: use strict; [In reply to] Can't Post

Using local() does not declare a variable.

use strict; 
local $foo;

That will not go over well with strict.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


Feb 24, 2001, 7:31 PM

Post #5 of 5 (519 views)
Re: use strict; [In reply to] Can't Post

(in reply to japhy) as I just found out :x

Jeffrey "muinatit" Lamoureux


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives