in reply to Re: Dynamically Assigning 1 array to another
in thread Dynamically Assigning 1 array to another

OK. So I'm having some problems with dereferencing.
I am trying to iterate through the items with this..


foreach my $servers (@{$masterlist{$servtype}}){
print "Let's see $servers \n";
print RESULT " members $servers".":$serviceport\n";
}


When $servtype is explicitly defined it works fine, at least for that array. But when I put $servtype in there it doesn't work.
The $servtype variable has the same values as the array name. It SHOULD work but I must be dereferencing something improperly.
  • Comment on Re^2: Dynamically Assigning 1 array to another

Replies are listed 'Best First'.
Re^3: Dynamically Assigning 1 array to another
by Anonymous Monk on Nov 05, 2010 at 23:58 UTC
    #! /usr/bin/env perl use strict; use warnings; my %masterlist = ( foo => [ 1, 2, 3, ], bar => [ 'a', 'b', 'c', ], ); my $servtype = 'bar'; for my $servers (@{$masterlist{$servtype}}) { print "$servers\n"; }
    Output:
    a b c
Re^3: Dynamically Assigning 1 array to another
by LanX (Saint) on Nov 05, 2010 at 23:57 UTC
    Sorry I don't understand ... could you please elaborate what your problem is?

    Cheers Rolf