in reply to Global symbol requires explicit package name

Hi,

Any idea how I can get rid of it? "Global symbol "@state" requires explicit package name"
There are several things not quite correct with your script.

When all that was "taken" out of the way. There is still a " scalar" variable called $state though declared, but then used as an Array of Array!!!
Though there is a subroutine called "&make_shared_array();" which was not showed in your script. And you shouldn't call Perl 5 subroutine as Perl 4, expect in some other cases, where subroutine refrenece is needed. Even in that you can still come around it!
How I got rig of the error message:
To make the script work. Corrected all mention above. And then commented "OUT" this line my $state = &make_shared_array(); since the subroutine "make_shared_array()" was not given, then in the PLACE of the INTENDED AoA variable $state, I used the variable "$tmp".
I don't know if that is permited. If not you might have to check that out and fix the variable $state that is "supposed" to be used. But am sure, the usage should be in the way I used $tmp.
But really, really, I don't know what the subroutine " make_shared_array()" returns.

Modified script:
#!/usr/bin/perl use warnings; use strict; use threads::shared; my $tmp = meow(); #my $state = &make_shared_array(); for ( my $i = 0 ; $i < 2 ; $i++ ) { for ( my $j = 0 ; $j < 6 ; $j++ ) { print "$tmp->[$i][$j] \n"; } } my @array = (); #for(my $i=0; $i<222; $i++){ for ( my $j = 0 ; $j < 222 ; $j++ ) { $array[$j] = $tmp->[1][$j]; } if ( $array[0] eq $tmp->[1][0] ) { print " array[0] eq $array[1] \n"; } sub meow { my $i = 0; my $j = 1; my $state = []; ### added Array Ref my @p = ( "grey", "striped", "purrr", "cutest_kitty", "meowing_kitty", "the_lord_of_the_cats" ); my @k = ( "smart_kitty", "striped_sweety", "purrr", "meowing_poes", "social_kitty", "the_lord_of_the_poezen" ); for ( my $f = 0 ; $f < 6 ; $f++ ) { push( @{ $state->[$i] }, $p[$f] ); ### always remember the +arrow -> push( @{ $state->[$j] }, $k[$f] ); ### always remember the +arrow -> } return $state; ### added explict return }
You also do not want to use C for loop in Perl. Though it works, but Let make Perl speak Perl not other language.:)
You might have to check out the following for detailed Info:
perldoc perldsc,
perldoc perllol,
perldoc perldata,
perldoc perlref

Hope this helps.

Replies are listed 'Best First'.
Re^2: Global symbol requires explicit package name
by bebe (Novice) on Aug 13, 2012 at 06:58 UTC
    Thank you so much for your detailed reply. Sorry I left out this subroutine.
    The reason I'm using this is to share the array of arrays. I'm very new with perl how do you suggest I share this array of array instead of using this subroutine?


    sub make_shared_array {
    my $a = &share([]);
    for (my $i = 0;$i <6 ; ++$i) {
    my $row = &share([]);
    $a->[$i] = $row;
    }
    return $a;
    }
    Thank you so much!!! I greatly appreciate all your help
      hi,

      how do you suggest I share this array of array instead of using this subroutine?

      from your Code:
      What is &share([]);?
      Are you trying to call a Subroutine reference within another subroutine, then assign to a scalar variable? Really, I don't know what you want to achieve here Please.
      You probably have to include all the subroutine you are trying to use.

Re^2: Global symbol requires explicit package name
by bebe (Novice) on Aug 13, 2012 at 16:59 UTC

    Thank you so much for your advice... I tried your solution! it works and I no longer get the Global symbol ... error. :-)
    However I now get a new error message:
    Use of uninitialized value in string eq at sharingpoes.pl line 30. Use of uninitialized value in string eq at sharingpoes.pl line 30.
    I'm the cutest kitty ever
    Use of uninitialized value in concatenation (.) or string at sharingpoes.pl line 31.
    array[0] =


    if ( $array[0] eq $tmp->[1][0] ) { #line 30
    print " array[0] eq $array[1] \n"; # line 31
    }

    Thank you so very much!