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

Thanks for the replies. I really do appreciate it!
Now I want to expand this a pinch, now that some of you think my deleting of hash keys is not needed.
I have two hash tables (%runset and %description) and I want to do the following. All of the keys in %runset have precendence over %description. BUT if there are "new" ones in %description, I don't want to forget those either.. So here was my thoughts on how to do this..
1. Only valid runset variables in %runset are Uppercase(This is why deleting them is easier..)
2. Comparing the two hashes grab %runset first and as you print them delete them from both hashes (if they exist in %description - which they might not).
3. Now any remaining hashes in %description print them as well.
Am I crazy?
If you want to try your hand at this code I would really be indebted to you all. Thanks much!!
  • Comment on Re: Parsing a hash table for only variables that are uppercase.

Replies are listed 'Best First'.
Re: Re: Parsing a hash table for only variables that are uppercase.
by rob_au (Abbot) on Mar 24, 2002 at 01:34 UTC
    This is actually much easier than you might expect - Essentially you are looking at merging two hashes with the key-values of %runset having precedence of those in %description. This can be done as follows:

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

    This code will delete the non-uppercase key-value pairs in the %runset and then merge the two hashes - Any values in %description with an identical key-name in %runset will be replaced with the values in the latter (based on left-to-right execution).

     

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

      Hi Rob,

      Thanks for sharing your knowledge. Even in your .sig?

      I tried pasting your .sig:

      $ $ perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print' In string, @cowsnet now must be written as \@cowsnet at -e line 1, nea +r "rob@cowsnet" Execution of -e aborted due to compilation errors. $ perl -e 's&&rob\@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print' rob@cowsnet_au$

      Am I missing something?

      HTH, Danny

      Update:

      $ perl -v This is perl, v5.6.0 built for i586-linux Copyright 1987-2000, Larry Wall . . .
        *chuckle* ... It looks like its time for me to update my .sig - Thanks for the tip mAsterdam++

         

        Save Ferris? Forget that ... Save tilly! [1]