What everyone has said so far is ways to list all the VALUES contained in a
hash array, what I need to do is list all the KEYS contained in the hash
array-with a tab (\t) between each.
Cheers,
-Shannon
> From: [EMAIL PROTECTED] (Fliptop)
> Organization: Peace Computer Systems
> Reply-To: [EMAIL PROTECTED]
> Newsgroups: perl.beginners.cgi
> Date: Wed, 24 Oct 2001 08:15:12 -0400
> To: Shannon Murdoch <[EMAIL PROTECTED]>
> Cc: [EMAIL PROTECTED]
> Subject: Re: Printing Hash Keys
>
> 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]