Front page | perl.beginners |
Postings from July 2003
Re: joining keys
Thread Previous
|
Thread Next
From:
Kevin Pfeiffer
Date:
July 11, 2003 13:02
Subject:
Re: joining keys
Message ID:
5944766.Rz0gKUxgXo@sputnik.tiros.net
In article <20030711172813.90583.qmail@onion.perl.org>, Rob Dixon wrote:
> Well done Kevin!
>
> Just a couple of points.
Am I surprised? ;-)
>> sub pad_keys {
>> my $ref = shift;
>> if (ref $ref eq "HASH") {
>> for my $value (%$ref) {
>
> This will loop over all the keys and values in the
> hash, in the order key1, value1, key2, value2, ...
> All you want is the values.
You mean that the last line should be:
for my $value (values %$ref) { # ?
[...]
> Finally, there's no need process the values and then the keys
> in separate loops. Each execution of either loop corresponds to
> a key/value pair so you can write
>
> foreach (keys) {
> modify key;
> recurse on value;
> }
After looking at your example I see what you mean.
[...]
> next unless (my $new = $_) =~ tr/ /_/;
This tests true only if tr makes a translation?
>
> if (exists $ref->{$new}) {
> warn "Padded key $new already exists";
> }
> else {
> $ref->{$new} = delete $ref->{$_};
> }
> }
> }
Nice! Thanks for the tips.
--
Kevin Pfeiffer
International University Bremen
Thread Previous
|
Thread Next