Kevin Pfeiffer wrote:
> In article <[EMAIL PROTECTED]>, 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) { # ?
Yes. It works as it is only because none of the hash keys
are hash references so they're skipped.
> > 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.
Great.
> > next unless (my $new = $_) =~ tr/ /_/;
>
> This tests true only if tr makes a translation?
Yes. tr/// returns the number of substitutions it made in the object
string. So if there were no spaces it will return zero, which is false.
> >
> > if (exists $ref->{$new}) {
> > warn "Padded key $new already exists";
> > }
> > else {
> > $ref->{$new} = delete $ref->{$_};
> > }
> > }
> > }
>
> Nice! Thanks for the tips.
Welcome.
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]