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:
Why is there no error for "use strict"?


New User

Mar 30, 2005, 9:55 PM

Post #1 of 2 (646 views)
Why is there no error for "use strict"? Can't Post

I've been messing around with packages and modules and trying to get
variables accessible between them. However, I had a typo which I thought
that the "use strict" pragma would have caught. My simple script looks like

use strict;

print "Test variable: $not::here\n";

When I run "perl -c" on it, this is perfectly acceptable syntax, however I
never tried to "use" the "not" package as indicated here. Why isn't this an
error with "use strict"? And is there another way to detect such an error?
Should I get something that says I've tried to access a variable from another
package which is not in use in the script?

(Using "warnings" in this case tells me that I've used this only once....and
that is better, but still isn't good enough...I could use it twice and then that
doesn't show up either!)

Any ideas?


Thaumaturge / Moderator

Apr 1, 2005, 9:46 AM

Post #2 of 2 (625 views)
Re: [greent76] Why is there no error for "use strict"? [In reply to] Can't Post

There are a number of ways to get round strict's requirement that you pre-declare variables. One of them is that you give the variable a fully-qualified name. That means that you give it a name that contains at least one double semi-colon. All off the text before the final double semi-colon in the name is taken as the name of the symbol table that the variable is found in. Therefore your variable $not::there is interpreted as the variable $there in the symbol table 'not'.

As 'strict' does its checks at compile time there is no way for it to know which symbol tables will exist by the time the code is run and therefore it can't give an error for package variables that don't exist.

Dave Cross, Perl Hacker, Trainer and Writer
Get more help at Perl Monks


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

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