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: Variable scoping
by $Bill Luebkert other posts by this author
Jun 26 2003 11:57PM messages near this date
Variable scoping | Pair of key+value is the one and the only one in the hash
Moreno, Javier (GXS, Softtek) wrote:
>  Hi all,
>  
>  I have a question. After so much scoping issues and trying to understand
>  I am writing all my programs with use strict. However, I have some very
>  old code that I am trying to modify and get up-to-date. However there
>  are some programs that will require my code that I cannot touch.
>  Basically what I am trying to find out is if I can simply use globals in
>  the $::variable syntax. That is, if I simply replace all my 'globals'
>  with $:: will that work? Because I know this means 'main', but does it
>  mean 'my main'? That is, will those variables be scoped within my code
>  or within the code that is requiring it? In other words, will everything
>  work with use strict if I simply use $:: on all my variables? Is this a
>  way to 'globalize' my variables? I know I should probably write modules
>  but as I said this approach is complex and some parts out of my reach,
>  but I would like my code to be stable and up to today's perl standards.

The easiest thing to do until you can properly rewrite the code is to
add a use vars to the top of the file and include all of the variable that
had global scoping.  THen you can go through the code and fix the easy ones
like loop variables (a simple addition of my in the for/while) and such.
Later you can check the rest of them and make them more appropriate.  I like
to my each variable on the first usage (or before the block that it's in if
the scope is beyond the block).

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:dbecoll@[...].net
 (_/   /  )    // //       DBE Collectibles    Mailto:dbe@[...].com
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (Free site for Perl/Lakers)


_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Moreno, Javier (GXS, Softtek)
$Bill Luebkert

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