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.


In reply to Re: Global symbol requires explicit package name by 2teez
in thread Global symbol requires explicit package name by bebe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.