On Mon, 31 Jan 2005 13:40:01 -0800, Graeme St. Clair
<[EMAIL PROTECTED]> wrote:
> Combo ActiveState Perl 5.6.1 635 and Apache 1.0.xx from www.perl.apache.org
> <http://www.perl.apache.org> .
> 
> The following code goes round the foreach twice as often as I think it
> should.  (I realise the code is probably not particularly stylish, but I'd
> prefer to leave that alone for the moment.)
 
[cut] 

> my $counter = 0;
> foreach $capval ( sort bynumber %capdef ) {
>   $counter++; # debug
>   if (defined $capdef{$capval}) { # debug
>     print STDERR $counter . " " . $capval . " " . Dumper($capdef{$capval}) .
> "\n"; # <-- print 2
>     my @elcdev = split(/;/, $capdef{$capval}{'ELIGELC'});
>     my @tlcdev = split(/;/, $capdef{$capval}{'ELIGTLC'});
>     # Useful stuff originally went here.
>   } else { # debug
>     print STDERR "Haha!" . $counter . "\n"; <-- print 3 debug
>   } # debug
> }
> 
> exit 0;

[cut]

> 'print 2' shows 171 items as expected.
> 
> And then --- I get Haha!172 thru Haha!342 from 'print 3'.
> 
> What is going on that I haven't understood?
> 
> Rgds, GStC.


Graeme,

I think you're looking for:

foreach $capval ( sort bynumber( keys %capdef) ) {

I forget what exactly 'sort %hash' (as opposed to 'sort keys %hash')
does, but not what you want.

HTH.

--jay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to