[32131] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3396 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 31 14:09:20 2011

Date: Tue, 31 May 2011 11:09:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 31 May 2011     Volume: 11 Number: 3396

Today's topics:
        our is not our <nospam.gravitalsun@hotmail.com.nospam>
    Re: our is not our (Randal L. Schwartz)
    Re: our is not our <uri@StemSystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 31 May 2011 03:03:20 +0300
From: George Mpouras <nospam.gravitalsun@hotmail.com.nospam>
Subject: our is not our
Message-Id: <is1b8d$1tpq$1@news.ntua.gr>

# The following should work,any idea why it doesn't ?
# Global symbol "@array" requires explicit package name at test.pl line 4

#!/usr/bin/perl
use strict;
foo();
print @array;
sub foo { our @array=(1..3) }


------------------------------

Date: Mon, 30 May 2011 17:27:10 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: our is not our
Message-Id: <86ei3fsoip.fsf@red.stonehenge.com>

>>>>> "George" == George Mpouras <nospam.gravitalsun@hotmail.com.nospam> writes:

George> # The following should work,any idea why it doesn't ?
George> # Global symbol "@array" requires explicit package name at test.pl line 4

George> #!/usr/bin/perl
George> use strict;
George> foo();
George> print @array;
George> sub foo { our @array=(1..3) }

Nope.  The first use of @array *lexically* does not have "our" in front
of it.  It's a compile-time thing, not a run-time thing.

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion


------------------------------

Date: Mon, 30 May 2011 23:33:57 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: our is not our
Message-Id: <87oc2jpmqi.fsf@quad.sysarch.com>

>>>>> "GM" == George Mpouras <nospam.gravitalsun@hotmail.com.nospam> writes:

  GM> # The following should work,any idea why it doesn't ?
  GM> # Global symbol "@array" requires explicit package name at test.pl line 4

it shouldn't work as it is written.

  GM> #!/usr/bin/perl
  GM> use strict;
  GM> foo();
  GM> print @array;

@array isn't declared yet. strict tells you that.

  GM> sub foo { our @array=(1..3) }

that declares @array only inside the sub.

our is simple to understand but it is usually poorly explained. it is
just a lexical shortcut to a package global var. so it declaration is
scoped to the smallest block enclosing it or the file. in your case it
is only in the sub. it doesn't create anything else. your code needs to
have our @array before the print line and it will work.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3396
***************************************


home help back first fref pref prev next nref lref last post