eval array name 2, and 'my'

When I declare three global arrays in a mod B.pm thus

@eth;
@meth;
@prop;

the following works just fine.  

    foreach $n (qw(eth meth prop)) {
      foreach $t (eval "\@$n") {
        print $t;
    }}

    # just be sure
    print $eth[0];
    print $eth[1];
    print $eth[2]

If I declare the arrays with 'my'

my @eth;
my @meth;
my @prop;

The eval fails. The 'hard' coded indexed prints do not.  What's going on?
LVL 1
hank1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Adam314Commented:
what error do you get?
hank1Author Commented:
I didn't get anything!  I also put a print inbetween the 2 foreach structs -
just to  insure it was motoring.  Was.
hank1Author Commented:
Also might add that this foreach loop is within another sub in the module B.pm

For now I just took out my my's :-)  and it works just fine.


Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

hank1Author Commented:
or is that fine fine.  TOO much coffee.
ozoCommented:
where did you set $eth[0]?
hank1Author Commented:
Was set within B.pm by a call from the main script.  Package names differ.
ozoCommented:
Could you show a complete example of code that fails?
hank1Author Commented:
Here are two files that demonstrate the 'my'.  "x.pl"
call two subs in "HPLC.pm".  When the array @note is
'my'd, the sayNotes() eval creates no note array output.  

#--------------------------- x.pl
  use HPLC;
  HPLC::demofill();
  HPLC::sayNotes();


#--------------------------- HPLC.pm
  package HPLC;
  my $bug = 0;
  $bug = 1;

  BEGIN {
    use Exporter ();
    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
    $VERSION = 1.02;
    @ISA =         qw(Exporter);
    @EXPORT =      qw();
    %EXPORT_TAGS = ();
    @EXPORT_OK =   qw();
  }
  our @EXPORT_OK;

   @reagent;
   @created;
   @type;  
   @type2;
   my @note;

   @line_items;


  sub
  demofill {

    $note[0] = "Note one.";
    $note[1] = "Note two.";
    $note[2] = "Note three.";
    $note[3] = "Note four.";

  }

  # ------------------------------------------------------------------------
  sub
  sayNotes {
    foreach my $n (qw(reagent created type type2 note)) {
      $bug and print qq/array name: "$n"\n/;
      foreach my $val (eval "\@$n") {
        print qq/Value of notes $n is  $val\n\n/;
      }
    }

    #print $note[0] . "\n";
    #print $note[1] . "\n";
    #print $note[2] . "\n";
    #print $note[3] . "\n";

  }

  1;
ozoCommented:
 sub
  sayNotes {
    foreach my $n (qw(reagent created type type2 note)) {
      $bug and print qq/array name: "$n"\n/;
      foreach my $val (eval "\@$n") {
        print qq/Value of notes $n is  $val\n\n/;
      }
    }

    print $note[0] . "\n";
    #print $note[1] . "\n";
    #print $note[2] . "\n";
    #print $note[3] . "\n";

  }
ozoCommented:
or
 our @note;
hank1Author Commented:
Yes, does seem to work with 'our' ..  but it also works without 'my' and with
local.  I'll have to readup on 'our'.  Hope the definition of 'our' explains why
'my' doesn't work.  Thanks
ozoCommented:
It seems to work with my if you also use the array in the sub not in an eval
it seems to be more a peculiarity of using eval.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.