in reply to (Guildenstern) REx6: Populating a Hash: Can someone help me to understand?
in thread Populating a Hash: Can someone help me to understand?
I find that removing the autovivication can make the code easier to understand (and I wish there was a way to force this):
my %ttys= (); open( WHO, "who|" ) or die "Can't fork to read from who: $!"; while( <WHO> ) { my( $user, $tty )= split; if( ! exists $ttys{$user} ) { $ttys{$user}= [$tty]; } else { push @{$ttys{$user}}, $tty; } } foreach my $user ( sort keys %ttys ) { print "$user: @{$ttys{$user}}\n"; }
The if shows a bit of what happens under the covers in the previous example.
- tye (but my friends call me "Tye")
|
---|
Replies are listed 'Best First'. | |
---|---|
(Guildenstern) REx8(!): Populating a Hash: Can someone help me to understand?
by Guildenstern (Deacon) on Sep 19, 2000 at 20:58 UTC |