Mark Hanson wrote:
> 
> Hi!
> 
> Yet another hash question:
> 
> How can I permanently modify a hash key? I have the following hash:
> 
> my %hash = (
>         hygiene_products_total_amount => {
>                 'conditioner' => "5",
>                 'shampoo'       => "57",
>                 'soap'  => "1",
>         },
>         cleaning_products_total_amount => {
>                 'mops' => "20",
>         },
> );
> 
> I tried the following which prints out the correct value, but doesn't permanently 
>modify the key.
> 
> #removing all but two underscores
> foreach (keys %hash) {
>         $count = $_ =~ s/(_)/$1/gi;
>         while (($count = $_ =~ s/(_)/$1/gi) > 2) {
>                 $_ =~ s/_//;
>         }
> print "\n$_\n";
> }


while ( my ( $key, $val ) = each %hash ) {
    ( my $newkey = $key ) =~ tr/_//d;
    $hash{ $newkey } = $val;
    delete $hash{ $key };
    }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to