Re: hash issue

2013-04-19 Thread Jim Gibson
On Apr 19, 2013, at 6:45 AM, Peter Scott wrote: > On Wed, 17 Apr 2013 11:47:49 -0700, Jim Gibson wrote: >> 1. You should not modify a hash while you are iterating through it with >> the each() function. The each() function uses an internal data structure >> that persists from one call of each to

Re: hash issue

2013-04-19 Thread Peter Scott
On Wed, 17 Apr 2013 11:47:49 -0700, Jim Gibson wrote: > 1. You should not modify a hash while you are iterating through it with > the each() function. The each() function uses an internal data structure > that persists from one call of each to the next. That internal data > structure can be modifie

Re: hash issue

2013-04-17 Thread Uri Guttman
On 04/17/2013 02:45 PM, Andy Bach wrote: while ( ($key2, $value2) = each %names ) { and the better idiom is; foreach my $key ( keys %names ) { print "got: $key => $names{$key}\n" } actually IMO the while/each loop is the better (and lesser known) idiom. it is more efficient as you don't

Re: hash issue

2013-04-17 Thread Uri Guttman
On 04/17/2013 02:45 PM, Andy Bach wrote: loop: while ( ($key2, $value2) = each %names ) { and the better idiom is; foreach my $key ( keys %names ) { print "got: $key => $names{$key}\n" } actually IMO the while/each loop is the better (and lesser known) idiom. it is more efficient as you

Re: hash issue

2013-04-17 Thread Jim Gibson
On Apr 17, 2013, at 11:17 AM, Irfan Sayed wrote: > hi, > need help on hashes > here is the code : > > > print "Enter the words: "; > chomp(my @words = ); > > my %names; > > foreach $a (@words) { > if (!%names) { > print "hi\n"; > $names{$a} = 1; > } else { > while ( ($key, $value) = each %na

Re: hash issue

2013-04-17 Thread Andy Bach
On Wed, Apr 17, 2013 at 1:17 PM, Irfan Sayed wrote: > please suggest You need to work on indenting! Name a hash and an array the same is going to lead to troubles down the road. The standard idiom for going through a hash is to just get the key and the ref the value via the hash: foreach my $ke

hash issue

2013-04-17 Thread Irfan Sayed
hi, need help on hashes  here is the code : print "Enter the words: "; chomp(my @words = ); my %names; foreach $a (@words) { if (!%names) { print "hi\n"; $names{$a} = 1; } else { while ( ($key, $value) = each %names ) { if ($a eq $key) { $names{$key} += 1; } else { $names{$a} = 1; } } } } for

Re: hash issue

2005-03-22 Thread Chris Knipe
: Allrighty The module is called from FreeRadius itself, so if : there really is nothing wrong with my code (which I suspect there : isn't), then I guess this must be moved to the FR list. But let's : rather make sure it's not the code first. To set up a test case we can assume that the w

RE: hash issue

2005-03-22 Thread Charles K. Clarkson
Chris Knipe wrote: : Allrighty The module is called from FreeRadius itself, so if : there really is nothing wrong with my code (which I suspect there : isn't), then I guess this must be moved to the FR list. But let's : rather make sure it's not the code first.

Re: hash issue

2005-03-22 Thread Chris Knipe
eq "Ethernet" && $RAD_REQUEST{'Framed-Protocol'} eq "PPP") { # PPPoE } elsif ($GlobalDB) { return RLM_MODULE_NOOP; } else { return RLM_MODULE_FAIL; } } # Accounting Request sub accounting { return RLM_MODULE_OK; } sub detach { &radius

RE: hash issue

2005-03-22 Thread Charles K. Clarkson
Chris Knipe wrote: : : i.e. : $RAD_REPLY{'Recv-Limit'} = "20971520"; : $RAD_REPLY{'Xmit-Limit'} = "20971520"; : works. : $RAD_REPLY{'Recv-Limit'} = $BytesAvail - $BytesUsed; : $RAD_REPLY{'Xmit-Limit'} = $BytesAvail - $BytesUsed; : doesn't

hash issue

2005-03-22 Thread Chris Knipe
Lo all, Snipette from the perl code... $RAD_REPLY{'Recv-Limit'} = $BytesAvail - $BytesUsed; $RAD_REPLY{'Xmit-Limit'} = $BytesAvail - $BytesUsed; $RAD_REPLY{'Reply-Message'} = "You have " . $za->format_bytes($BytesAvail - $BytesUsed) . " available."; Righty. $za->format_bytes

RE: Hash Issue

2003-11-01 Thread Bruce_Phillip
D] Cc: [EMAIL PROTECTED] Subject: Re: Hash Issue [EMAIL PROTECTED] wrote: > Wiggins, > >That works ok but still doesn't sort my keys correctly >Even if I use sort like so doesn't work. Like what I >have below: > > foreach my $OS (sort keys(%commands)) { >

Re: Hash Issue

2003-10-31 Thread Wiggins d'Anconia
[EMAIL PROTECTED] wrote: Wiggins, That works ok but still doesn't sort my keys correctly Even if I use sort like so doesn't work. Like what I have below: foreach my $OS (sort keys(%commands)) { while (my ($key, $command) = each (%{$commands{$OS}})) { print "$key running $comm

RE: Hash Issue

2003-10-31 Thread Bruce_Phillip
); That way I can index the file and use sort routine to do this: foreach my $OS (sort {lc($a) <=> lc($b)} keys(%commands)) { while (my ($key, $command) = each (%{$commands{$OS}})) { print "$key running $command\n"; } } Maybe that might work but then how

Re: Hash Issue

2003-10-31 Thread Wiggins d'Anconia
{ print "$key running $command\n"; } } http://danconia.org -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, October 31, 2003 12:33 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Hash Issue Hi, I've been playing around with

RE: Hash Issue

2003-10-31 Thread Bruce_Phillip
y. Any thoughts? Phillip -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, October 31, 2003 12:33 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Hash Issue > > Hi, > > > > I've been playing around with the Tie::IxHas

RE: Hash Issue

2003-10-31 Thread Bruce_Phillip
while (my ($key, $command) = each (%$OS)) { print "$key running $command\n"; } } -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, October 31, 2003 12:33 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Hash Issue > >

RE: Hash Issue

2003-10-31 Thread Bruce_Phillip
Wiggins, Thanks I'll try your suggestion and let you know What works. Phillip -Original Message- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Friday, October 31, 2003 12:33 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Hash Issue &g

Re: Hash Issue

2003-10-31 Thread Wiggins d Anconia
> > Hi, > > > > I've been playing around with the Tie::IxHash module. > > > > Here is my part of my code: > It appears to be lacking, use strict and use warnings these will help you track down on your own your errors > > > tie my %commands, "Tie::IxHash"; > > > > %comman

Hash Issue

2003-10-31 Thread Bruce_Phillip
Hi, I've been playing around with the Tie::IxHash module. Here is my part of my code: tie my %commands, "Tie::IxHash"; %commands = ('sol'=>{'hostname' =>'uname -n', 'os' =>'unamed -s', 'over' =>'un

RE: Hash Issue or Understanding

2003-10-30 Thread Bruce_Phillip
Sudarshan, Thanks for the info. I understand now and makes sense. Phillip -Original Message- From: Sudarshan Raghavan [mailto:[EMAIL PROTECTED] Sent: Thursday, October 30, 2003 1:51 AM To: [EMAIL PROTECTED] Subject: Re: Hash Issue or Understanding >The output works but it not in

RE: Hash Issue or Understanding

2003-10-30 Thread Bruce_Phillip
Gary, Thanks for the feedback. Phillip -Original Message- From: Gary Stainburn [mailto:[EMAIL PROTECTED] Sent: Thursday, October 30, 2003 1:47 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: Hash Issue or Understanding On Thursday 30 Oct 2003 8:17 am, [EMAIL PROTECTED] wrote

Re: Hash Issue or Understanding

2003-10-30 Thread Wiggins d Anconia
> On Thursday 30 Oct 2003 8:17 am, [EMAIL PROTECTED] wrote: > > it states in the perl docs that the sequence of the keys returned from a hash > cannot be guaranteed, and even if they always return in the same order in the > current version, that may change in a future version of perl. > Jus

Re: Hash Issue or Understanding

2003-10-30 Thread Gary Stainburn
On Thursday 30 Oct 2003 8:17 am, [EMAIL PROTECTED] wrote: > Hi, > > > >For those of you who helped me with my earlier scripts. Thanks. > > [snip] > > It seems to me the hash started almost at the bottom of the list instead of > > With the hostname and work it way down. Is there any way to force

Re: Hash Issue or Understanding

2003-10-30 Thread Sudarshan Raghavan
The output works but it not in the order I expected: I expected my output to be: hostname, IP addrress, OS, Version, Release, Server Type, Model, Memory Size, Total CPU's. But what I got was: Model, Server Type, cpu, Release, hostname, OS, Memory Size, Version It seems to me the hash sta

Hash Issue or Understanding

2003-10-30 Thread Bruce_Phillip
Hi, For those of you who helped me with my earlier scripts. Thanks. But I have a further problem in understanding something. Using The following declaration: my %commands = ('sol'=>{'hostname' =>'uname -n', 'os' =>'uname