ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
Re: Help with strict
by Bill Luebkert other posts by this author
Aug 22 2008 5:13PM messages near this date
Re: Help with strict | HOWTO Build a .pm File
Barry Brevik wrote:
>  I have seen it said many times, on this list, that we should always
>  have:
>   
>    use strict;
>  
>  I have tried to use this many times, but all it does is give me hundreds
>  of errors like this:
>   
>    Global symbol "$version" requires explicit package name at
>  domainctrl.pl line 10.
>    Global symbol "%cmptrlist" requires explicit package name at
>  domainctrl.pl line 18.
>  
>  All of these are variables created in the main body of the program... I
>  suppose that they are technically part of the "main" package, but if
>  strict is trying to tell me that I have to refer to these as
>  main::$version (for example), I don't think that I am willing to go
>  there.
>  
>  Can anyone tell me what is going on here?

All you have to do is define them one first use or somewhere prior to
first use for globals.

Rather than saying :

	$status = get_status ();

try using 'my' (define and allocate memory) or 'our' (just define) to
predefine the variable prior to use :

	our $status;	# or my $status = <some-initial-value> ;

	...		# some intervening code

	$status = get_status ();

or at the time of first use (what I do in most cases unless it needs to
be a global used in other subs in which case you would pre-define) :

	my $status = get_status ();

Once you've given your intention to use a variable, you won't get an error
when you actually do and if you do get the error it will help you find
logic erros in your script.
_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Barry Brevik
Lyle
Brian Raven
Serguei Trouchelle
Bill Luebkert

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved