Link to home
Start Free TrialLog in
Avatar of bt707
bt707Flag for United States of America

asked on

Perl grep from array


I have the following array @fimAttributes but have changed it to have two sections, one for blue and one for yellow in this example.

I was using a grep to preform a function based on if the attribute was in the array, but now that I have changed it to two sections in the array I'm not sure how to do the grep on the section that I want.

From the example below, how do I change the grep to grep the blue or yellow section of the array, something simple I'm sure, just not sure what I need to change the grep line to?

Thanks,

my @fimAttributes=(q{blue}=>[qw{
                            id
                            alias
                            c
                            cn
                            department
                            displayname
                            facsimiletelephonenumber
                            givenname
                            manager
                            jobtitle
                            userprincipalname}],
                    q{yello}=>[qw{  
                            givenname
                            jobtitle
                            l
                            mail
                            mailalias
                            mailalternateaddress
                            mobile
                            o
                            ou
                            userprincipalname}]
                );




my (@Attributes)=('cn','mail','manager','securitystatus','alias','itbuilding');

    my @Attributes1;
    foreach my $i (0..$#Attributes) {
      unless (grep( /^$Attributes[$i]$/i, @fimAttributes) ) {       
        push(@Attributes1,$Attributes[$i]);
      }
    }
    @Attributes=@Attributes1;

foreach my $att (@Attributes) {
  print "$att\n";
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sjklein42
sjklein42
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bt707

ASKER

That's pretty much what I tried but I see I had a mistake.

Thanks,