Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Dynamically Assigning 1 array to another

by Fletch (Bishop)
on Nov 05, 2010 at 21:23 UTC ( [id://869758]=note: print w/replies, xml ) Need Help??


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.

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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://869758]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-03-19 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found