Sophia Corwell wrote:
> multiple values
> 
> 
> Sorry about that...
> 
> Here is an example:
> 
> Here is what my hash looks like:
> 
> %compilers = (
>    system1 => ['compiler_a'],
>    system2 => ['compiler_b',
> 'compiler_c','compiler_d'],
>    system3 => ['compiler_e'],
> );
> 
> Now, if I want to delete just the 'compiler_c' value
> from the system2 key, can I use the delete function or
> the pop function?
> 
> 
> --- Mark Anderson <[EMAIL PROTECTED]> wrote:
>> Could you give us an example?
>> 
>>              Thanks,
>>                      /\/\ark
>> 
>> -----Original Message-----
>> From: Sophia Corwell
>> [mailto:[EMAIL PROTECTED]]
>> Sent: Thursday, January 09, 2003 3:58 PM
>> To: [EMAIL PROTECTED]
>> Cc: [EMAIL PROTECTED]
>> Subject: Removing a specific value from a hash whose keys contains
>> multiple values
>> 
>> 
>> I am not sure how to delete a specific value from a
>> hash whose keys contains multiple values.
>> 
>> Could anyone advice, please?
>> 
>> Thanks,
>> 
>> Sophia
Given your setup, here is a start:

my %compilers = (
   system1 => ['compiler_a'],
   system2 => ['compiler_b',
'compiler_c','compiler_d'],
   system3 => ['compiler_e'],
  );
my $MyCheck = 'compiler_c';     # what I want to remove
my @MyDelete = ();              # hold indexes which I want to delete
my $MyDelPrt = '';              # whether item deleted or not

printf"Original List:\n";
foreach my $MyKey ( keys %compilers ) {
    printf "%-s(", $MyKey;                              # Print main Key
    my $MyMax = scalar(@{$compilers{$MyKey}});  # Get the number of items in
the array
    printf "%2d):\n", $MyMax;
    for(my $MyId=0;$MyId<$MyMax;$MyId++) {
        $MyDelPrt = '';
        if ( $compilers{$MyKey}[$MyId] =~ /\Q$MyCheck\E/i ) {  # if matches
what looking for
            push( @MyDelete, $MyId);                               # push on
to delete array
            $MyDelPrt = '(d)';                                     # part to
display
         }
        printf "  %-s%-4s",$compilers{$MyKey}[$MyId], $MyDelPrt;
     }
    printf "\n";
    foreach ( @MyDelete ) {
        splice(@{$compilers{$MyKey}},$_,1);                       # remove
the items found if any
     }
 }

printf"Modified List:\n";                                                 #
Reprint the modified array
foreach my $MyKey ( keys %compilers ) {
    printf "%-s(", $MyKey;
    my $MyMax = scalar(@{$compilers{$MyKey}});
    printf "%2d):\n", $MyMax;
    for(my $MyId=0;$MyId<$MyMax;$MyId++) {
        printf "  %-s",$compilers{$MyKey}[$MyId];
     }
    printf "\n";
 }

Output:

Original List:
system1( 1):
  compiler_a
system2( 3):
  compiler_b      compiler_c(d)   compiler_d
system3( 1):
  compiler_e

Modified List:
system1( 1):
  compiler_a
system2( 2):
  compiler_b  compiler_d
system3( 1):
  compiler_e


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


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

Reply via email to