Shannon Murdoch wrote: > > > From: [EMAIL PROTECTED] (Brett W. McCoy) > > > > On Wed, 24 Oct 2001, Shannon Murdoch wrote: > > > >> I know how to print the contents of a hash, but what if I wanted to print > >> the keys themselves that the hash is called from (delimited by tabs)? > >> > >> This is how I print the contents of a hash (Thanks to Brett W. McCoy): > >> > >> %params = qw( > >> i01 4 > >> i02 5 > >> i03 2 > >> ); > >> > >> foreach (sort keys %params) { print "\t$params{$_}" } > > > > The same way. $_ is the key for the hash element in the while loop. > > I want a list of keys, not their values though.
you can do it like this: foreach (sort(keys(%params))) { print "$_: $params{$_}\n"; } or like this (which, to me, is easier to read): foreach my $key (sort(keys(%params))) { print "$key: $params{$key}\n"; } perldoc -f keys perldoc -f values -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]