Solved

Perl grep from array

Posted on 2011-03-11
2
388 Views
Last Modified: 2012-05-11

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

0
Comment
Question by:bt707
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 35111685
Change fimAttributes to be a hash, and then cast it where used on line 33:

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{'blue'}}) ) {       
        push(@Attributes1,$Attributes[$i]);
      }
    }
    @Attributes=@Attributes1;

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

Open in new window

0
 

Author Closing Comment

by:bt707
ID: 35111707
That's pretty much what I tried but I see I had a mistake.

Thanks,
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question