Here's one way to go about it.  It sounds to me like an array of hashes will
work just fine for you.

Let's say you have an array:

  my @routers = ();

You can do a 

  push @routers,"stimpy";

to add a scalar to the end, but you can also add an entire hash indirectly
by using hash references:

  #Example 1:
  push @routers,\%infohash;
  #Example 2:
  push @routers,{name => "stimpy", brand => "ren", model =>
"powdered_toast"}

In example 2, I created an anonymous hash and added it to the end, which has
the same effect as example 1 except that I didn't have to already have a
hash created.

The end result is that once I've created an array of hash references, I can
do this:

  foreach(@routers){
    print(sort keys %{$_});#dereference
    print "$_->{name}\n";  #access indirectly
  }

Check out "perldoc perllol" (list of lists) for more info.


-----Original Message-----
From: Angerstein [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 26, 2002 4:47 AM
To: [EMAIL PROTECTED]
Subject: AW: use Variable as a hashname? 


It a little bit misunderstandable...

let´s say i got 100 hashes named after each of my routers.

a list auf my routeres is in @allmyrouters.

My hashes contains fileds: ip, interfaces, admin.

I want to access each hashes field admin in a loop.

How do i do that?

> -----Ursprüngliche Nachricht-----
> Von: Connie Chan [mailto:[EMAIL PROTECTED]]
> Gesendet am: Montag, 26. August 2002 13:38
> An: Angerstein; [EMAIL PROTECTED]
> Betreff: Re: use Variable as a hashname?
>
> $x = 'key';
>
> %Y = ();
>
> $Y{$x} = 10;
>
> print $Y{key}; # You got 10;
>
> Rgds,
> Connie
>
>
>
> ----- Original Message -----
> From: "Angerstein" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, August 26, 2002 7:33 PM
> Subject: use Variable as a hashname?
>
>
> > Hello,
> > can I / how can I use a variable as a hash name?
> >
> > $$myVar{key}?
> >
> > Thanxs!
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to