the scope of BEGIN {}

2002-03-13 Thread Nikola Janceski

BEGIN {
if ($^O =~ /^(ms)?(win|dos)(32|nt)?$/i){
eval q{ 
use lib N:/xxx/perl_lib;
use Win32::Process;
use Win32::Event 1.00 qw(wait_any);

$follow = 0; # used in find command
$follow_skip = 0; # used in find command
}

} else {
eval q{ 
use lib /xxx/perl_lib;

$follow = 1; # used in find command
$follow_skip = 2; # used in find command
}
}
}

Here is my question, $follow and $follow_skip I want to be a global variable
in the scope of the perl script I am running.
If I put a my in front of the declaration wouldn't it only be in the scope
of BEGIN or would it be in the scope of the entire script? How can I declare
it so that use strict; and use warnings; won't complain?

(This has to be a global variable for I use it several subroutines and is OS
dependent).

Nikola Janceski

Too many of us look upon Americans as dollar chasers. This is a cruel libel,
even if it is reiterated thoughtlessly by the Americans themselves.
-- Albert Einstein (1879-1955) 




The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: the scope of BEGIN {}

2002-03-13 Thread Jason Larson

 -Original Message-
 From: Nikola Janceski [mailto:[EMAIL PROTECTED]]
 Subject: the scope of BEGIN {}
 
 
 BEGIN {
   if ($^O =~ /^(ms)?(win|dos)(32|nt)?$/i){
   eval q{ 
   use lib N:/xxx/perl_lib;
   use Win32::Process;
   use Win32::Event 1.00 qw(wait_any);
 
   $follow = 0; # used in find command
   $follow_skip = 0; # used in find command
   }
 
   } else {
   eval q{ 
   use lib /xxx/perl_lib;
 
   $follow = 1; # used in find command
   $follow_skip = 2; # used in find command
   }
   }
 }
 
 Here is my question, $follow and $follow_skip I want to be a 
 global variable
 in the scope of the perl script I am running.
 If I put a my in front of the declaration wouldn't it only be 
 in the scope
 of BEGIN or would it be in the scope of the entire script? 
 How can I declare
 it so that use strict; and use warnings; won't complain?
 
 (This has to be a global variable for I use it several 
 subroutines and is OS
 dependent).

I think you can do:
 use warnings;
 use strict;
 use vars qw($follow $follow_skip);

Hope this helps...
Jason


CONFIDENTIALITY NOTICE:



The information contained in this ELECTRONIC MAIL transmission
is confidential.  It may also be privileged work product or proprietary
information. This information is intended for the exclusive use of the
addressee(s).  If you are not the intended recipient, you are hereby
notified that any use, disclosure, dissemination, distribution [other
than to the addressee(s)], copying or taking of any action because
of this information is strictly prohibited.





Re: the scope of BEGIN {}

2002-03-13 Thread Michael Fowler

On Wed, Mar 13, 2002 at 01:27:08PM -0500, Nikola Janceski wrote:
 Here is my question, $follow and $follow_skip I want to be a global variable
 in the scope of the perl script I am running.
 If I put a my in front of the declaration wouldn't it only be in the scope
 of BEGIN or would it be in the scope of the entire script? How can I declare
 it so that use strict; and use warnings; won't complain?

If you put the declaration within the BEGIN block, yes, it would be scoped
to just that block.  So place the declaration outside of the BEGIN block.

my($follow, $follow_skip);
BEGIN {
...
}

Also, use strict is the only thing that complains about out-of-scope
variable usage, and it's more than just a complaint.


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]