Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Parsing a hash table for only variables that are uppercase.

by Albannach (Monsignor)
on Mar 24, 2002 at 00:28 UTC ( [id://153853]=note: print w/replies, xml ) Need Help??


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

Well since you say delete you could use something like
for (keys %runset) { unless($_ eq uc($_)) { delete $runset{$_}; } }
before your printing loop.

However you have another problem: a hash is un-ordered, so you won't get the sentence you expect unless you are very lucky - you need some way to specify the order in which the values of the uppercase keys are printed. The example you provide doesn't work for a simple sort of the uppercase keys so you'll have to think of something else.

--
I'd like to be able to assign to an luser

Replies are listed 'Best First'.
Re: Re: Parsing a hash table for only variables that are uppercase.
by Dice (Beadle) on Mar 24, 2002 at 17:16 UTC
    While it goes beyond the scope of the problem, a hash can be made to be ordered by using the CPAN module Tie::IxHash.

    Link to Tie::IxHash documentation
    Link to Tie::IxHash tarball

    Usage:

    #!/usr/bin/perl -w
    
    use strict;
    use Tie::IxHash;
    
    tie my %ordered_hash, Tie::IxHash;
    
    %ordered_hash = (a => 1, b => 2, c => 3);
    
    foreach my $key ( keys %ordered_hash ) {
        print "$key\t$ordered_hash{$key}\n";
    }
    
    # prints:
    # a     1
    # b     2
    # c     3
    
    exit 0;
    
    

    Cheers,
    Richard

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://153853]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-28 16:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found