Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > scope subroutine argument with "our"

Reply
Thread Tools

scope subroutine argument with "our"

 
 
pacmac
Guest
Posts: n/a
 
      10-01-2009
Hello All,

I'm trying to understand someone else's code. It's a mod_perl
PerlAccessHandler.

I'm not sure what's accomplished by "our" scoping an already-our-
scoped variable when passed as an argument to a subroutine. See the
way check_pwd() is called below. Does doing this make a copy? I don't
get it.

Can someone please enlighten me?
PM

package myControl;

use strict;

use [typical Apache2 modules];

our $PWD_SECRET = '128XYZ345';

sub handler {
my $r = shift;
...
my ($stat, $msg) = check_pwd($r, our $PWD_SECRET);
...
}

sub check_pwd {
my $r = shift;
my $secret = shift;

... do stuff ...
return (1, 'OK');
}
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      10-01-2009
>>>>> "p" == pacmac <(E-Mail Removed)> writes:

p> I'm not sure what's accomplished by "our" scoping an already-our-
p> scoped variable when passed as an argument to a subroutine. See the
p> way check_pwd() is called below. Does doing this make a copy? I don't
p> get it.

p> package myControl;

p> our $PWD_SECRET = '128XYZ345';

p> sub handler {
p> my $r = shift;
p> ...
p> my ($stat, $msg) = check_pwd($r, our $PWD_SECRET);
p> ...
p> }

AFAIK it doesn't do anything special. the outer our is file scoped so
the inner one is redundant. both will refer to the same package
variable. the coder probably didn't understand the scoping rules of our
and thought our needed to be used in front of each use of that
variable. it only needs to be used the first time in a given scope.

uri

--
Uri Guttman ------ http://www.velocityreviews.com/forums/(E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
 
C.DeRykus
Guest
Posts: n/a
 
      10-01-2009
On Oct 1, 12:36*pm, pacmac <(E-Mail Removed)> wrote:
> Hello All,
>
> I'm trying to understand someone else's code. It's a mod_perl
> PerlAccessHandler.
>
> I'm not sure what's accomplished by "our" scoping an already-our-
> scoped variable when passed as an argument to a subroutine. See the
> way check_pwd() is called below. Does doing this make a copy? I don't
> get it.


The second "our" will draw a warning too if 'use warnings' is
in effect:

"our" variable $PWD_SECRET redeclared at ....

--
Charles DeRykkus
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      10-02-2009
>>>>> "CD" == C DeRykus <(E-Mail Removed)> writes:

CD> On Oct 1, 12:36*pm, pacmac <(E-Mail Removed)> wrote:
>> Hello All,
>>
>> I'm trying to understand someone else's code. It's a mod_perl
>> PerlAccessHandler.
>>
>> I'm not sure what's accomplished by "our" scoping an already-our-
>> scoped variable when passed as an argument to a subroutine. See the
>> way check_pwd() is called below. Does doing this make a copy? I don't
>> get it.


CD> The second "our" will draw a warning too if 'use warnings' is
CD> in effect:

you caught something there i missed but i wouldn't redeclare anyhow. if
both declarations were in the same namespace they would refer to the
same variable so the code still works. i bet since it is under mod_perl
the warnings (if ever seen) are tucked away in some log and only happen
at startup anyway. still a bad coding thing.

uri

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing argument to a subroutine ccc31807 Perl Misc 10 12-04-2009 12:39 AM
CSPEC issue: lossing scope (or incorrect scope) in cspec subroutine. balldarrens@gmail.com Perl Misc 0 02-05-2009 08:42 PM
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
Why declare "my $something" on top if it's going to get a lexical scope in a subroutine? GreenLeaf Perl Misc 3 02-24-2005 04:58 AM
substr() as subroutine argument -> weird behaviour nobull@mail.com Perl Misc 0 08-14-2003 06:19 PM



Advertisments