in reply to Parsing a hash table for only variables that are uppercase.

As always there are many ways to do this - the first which came to my mind was to use grep. eg.

foreach my $key ( grep { /^[A-Z]+$/ } keys %runset ) { print $key, " ", $runset{$key}, "\n"; }

... But if you really wanted to delete the non-uppercase hash elements, then expanding on this usage of grep ...

delete $runset{$_} for ( grep { !/^[A-Z]+$/ } keys %runset );

 

perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

Replies are listed 'Best First'.
Re: Re: Parsing a hash table for only variables that are uppercase.
by RSevrinsky (Scribe) on Mar 25, 2002 at 09:24 UTC
    Minor regex nit:

    Rather than checking the entire key for having uppercase letters and then negating the rest, you could check for the presence of any non-uppercase letter:

    delete $runset{$_} for ( grep { /[^A-Z]/ } keys %runset );

    Of course, this will also allow the null hash key as well, so you might want to extend the grep to grep { $_ && /[^A-Z]/ }, and by that point, you may have sacrificed the savings on the regex.

    - Richie