in reply to What am I doing wrong here?

Hi ginju75 - Even under use strict (which doesn't normally allow globals), you can declare globals with use vars qw($foo %bar) . Alternatively, you can 'switch off' this aspect of strict, within a limited scope, using no strict "vars".

But looking at your code, it doesn't look as though @X needs to be global - I'd rewrite it like this:

use strict; my $test = 'test'; my @X = values(); guest2(\@X, $test); sub values ( my @Y = qw(something something); return @Y; ) sub guest2 ( my @X = @{shift()}; # these copies of @X and $test my $test = shift ; # don't exist outside guest2() }
Have a read of perlman:lib:strict and perlman:perlsub.

hth,
andy.

Replies are listed 'Best First'.
Re: Re: What am I doing here?
by mce (Curate) on Dec 05, 2001 at 16:02 UTC
    Hi,

    good point about the use vars. In perl 56x there is also the our commando to define a global var. But, there was much discussion about this our, for example this and this.

    Just my 0.02 cents worth.
    ---------------------------
    Dr. Mark Ceulemans
    Senior Consultant
    IT Masters, Belgium