Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

using 'our' on Win32 vs Unix

by djbiv (Scribe)
on Jul 22, 2003 at 15:49 UTC ( [id://276779]=perlquestion: print w/replies, xml ) Need Help??

djbiv has asked for the wisdom of the Perl Monks concerning the following question:

ok.. not sure why this works on one system vs. the other. I have an application that should run on Win32 as well as *NIX systems. I declare several hash's using 'our %some_hash' and the associated values for the hash. here is an example:
our %hash = ( '1' =>'F,n,4', '2' =>'LL,n,19' );

this runs fine on Win32 system but when I run this on AIX I get the following error(s):
Bareword "our" not allowed while "strict subs" in use at program_name.pl line 139.
Bareword "fldFmt" not allowed while "strict subs" in use at program_name.pl line 139.
Operator or semicolon missing before %fldFmt at program_name.pl line 139.
Ambiguous use of % resolved as operator % at program_name.pl line 139.
Global symbol "%fldFmt" requires explicit package name at program_name.pl line 628.
Execution of program_name.pl aborted due to compilation errors.

perl on win32 is "v5.6.0 built for MSWin32-x86-multi-thread" and the version on AIX is "version 5.005_03 built for aix". Why do I get errors on one system vs. the other? Is this due to perl version / build differences?
PS. the program is runs fine using 'my' to declare the hash on both systems (technically the hash should be declared as a global according to programming perl by O'REILLY).

Replies are listed 'Best First'.
Re: using 'our' on Win32 vs Unix
by broquaint (Abbot) on Jul 22, 2003 at 15:54 UTC
    Is this due to perl version / build differences?
    Correct - our wasn't introduced into perl until 5.6.0. In the mean time you could use vars or just fully declare your variables
    use vars qw/%hash/; %hash = ( ... ); ## or %Your::Package::hash = ( ... );
    See. perldelta on your windows machine to for more information on the addition of our and any other changes between the two versions.
    HTH

    _________
    broquaint

      Thanks broquaint! ~Dan
Re: using 'our' on Win32 vs Unix
by dga (Hermit) on Jul 22, 2003 at 15:55 UTC

    I am not positive but I think 'our' is a later enhancement than your Unix version.

    You can use vars qw( %hash ); to make strict happy, but its not exactly the same as our.

    Alternately, of course, newer perls do support 'our'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://276779]
Approved by dga
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-23 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found