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

Global symbol "@points" requires explicit package name at ./exp.pl line 19. I can use: my @points; But is another way to fix it?

Replies are listed 'Best First'.
Re: Global vars
by moritz (Cardinal) on Mar 17, 2008 at 14:30 UTC
    Why do you want another way?

    For most situations lexical variables declared with my are exactly what you want.

    There are also "global" variables that are declared with our or (subtly diffent iirc) with use vars ($variables).

    You could also say no strict 'vars';, but that's a really bad idea unless you know what you're doing.

      Now I learned my ($a,$b,$c,$d) It was the problem Many "my" words in my code But thanks

        Alexseki as an aside, you might want to give the perlsyn documentation module a look, specifically search for 'Declarations', so you don't run into trouble with lexical variable scoping issues.

        Pancho
Re: Global vars
by olus (Curate) on Mar 17, 2008 at 14:36 UTC

    Proper way for working with variables is to declare them first. There are other options like our or local. Are you averse to variable declaration? Perl doesn't force you to declare the variables you work with if you do not use strictures and warnings, but who wants that?

      local doesn't declare a variable.