Home > Archive > PERL Beginners > March 2004 > hash
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| ewalker@micron.com 2004-03-29, 6:41 pm |
| any ideas on how I can access say all the values of a hash and not care =
what the keys are?
Thanks
| |
| James Edward Gray II 2004-03-29, 6:41 pm |
| On Mar 29, 2004, at 4:03 PM, ewalker@micron.com wrote:
> any ideas on how I can access say all the values of a hash and not
> care what the keys are?
Sure:
foreach (keys %some_hash) {
# do something with $_, which will hold one key at a time...
}
James
| |
| ewalker@micron.com 2004-03-29, 6:41 pm |
|
-----Original Message-----
From: James Edward Gray II [mailto:james@grayproductions.net]
Sent: Monday, March 29, 2004 3:06 PM
To: ewalker
Cc: beginners@perl.org
Subject: Re: hash
On Mar 29, 2004, at 4:03 PM, ewalker@micron.com wrote:
> any ideas on how I can access say all the values of a hash and not=20
> care what the keys are?
Sure:
foreach (keys %some_hash) {
# do something with $_, which will hold one key at a time...
}
James
ok thanks..
| |
| ewalker@micron.com 2004-03-29, 6:41 pm |
|
-----Original Message-----
From: James Edward Gray II [mailto:james@grayproductions.net]
Sent: Monday, March 29, 2004 3:06 PM
To: ewalker
Cc: beginners@perl.org
Subject: Re: hash
On Mar 29, 2004, at 4:03 PM, ewalker@micron.com wrote:
> any ideas on how I can access say all the values of a hash and not=20
> care what the keys are?
Sure:
foreach (keys %some_hash) {
# do something with $_, which will hold one key at a time...
}
James
Hey, That didn't work I didn't explain it right.=20
I have an array of hash pointers. Each hash has like 2 key/value pairs.
I want to travers the array and just print out the values from the =
hashes., Will I need to nest loops here?
Eric
| |
| Bob Showalter 2004-03-29, 6:42 pm |
| ewalker@micron.com wrote:
> any ideas on how I can access say all the values of a hash and not
> care what the keys are?
@arr = values %hash;
perldoc -f values
| |
| James Edward Gray II 2004-03-29, 6:42 pm |
| On Mar 29, 2004, at 4:09 PM, ewalker@micron.com wrote:
> James
>
> Hey, That didn't work I didn't explain it right.
> I have an array of hash pointers. Each hash has like 2 key/value pairs.
> I want to travers the array and just print out the values from the
> hashes., Will I need to nest loops here?
Probably, yes. Walk the array with the outer loop, then use the inner
loop I posted (or Bob's variation if you really don't need the key).
James
| |
| ewalker@micron.com 2004-03-29, 6:42 pm |
|
-----Original Message-----
From: James Edward Gray II [mailto:james@grayproductions.net]
Sent: Monday, March 29, 2004 3:18 PM
To: ewalker
Cc: beginners@perl.org
Subject: Re: hash
On Mar 29, 2004, at 4:09 PM, ewalker@micron.com wrote:
> James
>
> Hey, That didn't work I didn't explain it right.
> I have an array of hash pointers. Each hash has like 2 key/value =
pairs.
> I want to travers the array and just print out the values from the=20
> hashes., Will I need to nest loops here?
Probably, yes. Walk the array with the outer loop, then use the inner=20
loop I posted (or Bob's variation if you really don't need the key).
James
Thanks all
| |
| Wiggins D'Anconia 2004-03-29, 8:31 pm |
| ewalker@micron.com wrote:
>
> -----Original Message-----
> From: James Edward Gray II [mailto:james@grayproductions.net]
> Sent: Monday, March 29, 2004 3:06 PM
> To: ewalker
> Cc: beginners@perl.org
> Subject: Re: hash
>
>
> On Mar 29, 2004, at 4:03 PM, ewalker@micron.com wrote:
>
>
>
>
> Sure:
>
> foreach (keys %some_hash) {
> # do something with $_, which will hold one key at a time...
> }
>
> James
>
> Hey, That didn't work I didn't explain it right.
> I have an array of hash pointers. Each hash has like 2 key/value pairs.
> I want to travers the array and just print out the values from the hashes., Will I need to nest loops here?
> Eric
>
If you are just looking for debugging output take a look at
perldoc Data::Dumper
print Dumper(\%some_hash);
Will show you the entire structure.
http://danconia.org
|
|
|
|
|