in reply to Dynamically Assigning 1 array to another

You think you do, but you really want a hash of arrays. Read perlreftut and then see perldsc.

The cake is a lie.
The cake is a lie.
The cake is a lie.

  • Comment on Re: Dynamically Assigning 1 array to another

Replies are listed 'Best First'.
Re^2: Dynamically Assigning 1 array to another
by flyerhawk (Novice) on Nov 05, 2010 at 23:12 UTC
    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.
      #! /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
      Sorry I don't understand ... could you please elaborate what your problem is?

      Cheers Rolf

Re^2: Dynamically Assigning 1 array to another
by flyerhawk (Novice) on Nov 05, 2010 at 21:33 UTC
    I hadn't thought of that. Yeah that makes more sense. Thanks!