Wiggins: basically what I was trying to do is track a
counter value for each router in my network. These
routers may come and go. At some time I may have 10
routers at other times 100.
$Counter{$router1} = {n1, n2, n3, ...nN}
$Counter{$router2} = {m1, m2, m3, ...mN}
...
$Counter{$routerX} = ....
I guess I could use @{$Counter{$routerN}}
Thanks for the help.
Ravi
--- Wiggins d Anconia <[EMAIL PROTECTED]> wrote:
> Please bottom post...
>
> > True. Since the value(s) for @Counter$router is
> going
> > to be array, manipulating that hash was making
> things
> > complex for me.
> >
> > If I use a hash (%Counter), what do I have to do
> such
> > that the resulting value for $Counter{$router} is
> an
> > array.
> >
>
> You still haven't told us what you are really after.
> 'Counter' is a
> rather undescript variable name, and $router is just
> an IP address, so
> are you trying to count the number of times the IP
> occurs in a log,
> etc.? You haven't stated why you need an array
> associated with $router
> at all... the reason this is unclear is because of
> the name "Counter"
> which implies just a count, which implies a number,
> which implies a
> scalar, which if you really do need an array, this
> may suggest that your
> variable name is not terribly stylish...
>
> You have stumbled on references, which is a good
> thing in the end, but
> you need to first establish if you truly need an
> array, if you have in
> fact established this, then you should become
> familar with the core of
> references before leading yourself down the path of
> lots of questions. A
> look at,
>
> perldoc perlreftut
> perldoc perllol
> perldoc perldsc
> perldoc perlref
>
> Will probably help you the most...
>
> To specifically answer your question you can
> initialize the "slot" in
> the hash with an anonymous array reference like so:
>
> $Counter->{$router} = [];
>
> Then as your other message suggests you can act on
> that array in ways
> such as,
>
> push @{$Counter->{$router}}, 'My latest value';
> foreach my $value (@{$Counter->{$router}}) { # do
> something }
>
> Or individually as,
>
> $Counter->{$router}->[0]... but seriously read the
> docs....
>
> http://danconia.org
>
>
>
> > --- Wiggins d Anconia <[EMAIL PROTECTED]>
> wrote:
> > >
> > >
> > > > Hi: I have a existing variable called $router
> > > which is
> > > > "192.168.1.1". I want to create a array which
> > > looks
> > > > like @Counter192.168.1.1.
> > > >
> > > > @Counter.$router does not seem to work.
> > > >
> > > > Thanks in advance
> > > > Ravi
> > >
> > > The first question is why? I suspect first that
> the
> > > dots in the name of
> > > the variable will not be allowed for obvious
> reason,
> > > second you are
> > > trying to use symbolic references which are
> frowned
> > > upon, and prevented
> > > assuming you are doing 'use strict' (you are
> aren't
> > > you?).
> > >
> > > So what are you *really* trying to do? I will
> > > suggest a hash as usually
> > > this type of problem is solved by their use....
> > >
>
>
> --
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>