> 
> #!/usr/bin/perl -w
> use strict;
> use warnings;
> 
> my %hash = ( "acc12", 1,
>              "acc2",  0,
>              "acc3",  '',
>              "una1",  1 );
> 
> $hash{acc3} = ();
> 
> my $valid="acc1|acc2|acc3";
>


I'd get rid of the pattern matching and put the valid keys in their own
hash:

my %valid = (
        'acc1' => 1, 
        'acc2' => 1, 
        'acc3' => 1
        );


while (my ($key, $value) = each (%hash)) {

        if ($valid{$key})

### This seems cleaner to me. Also, if this has to be done many 
### times you should see an improvement in performance too, 
### but not if you only run through a short list once.

_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to