Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Comparing 2 arrays but ignoring certain patterns

by NetWallah (Abbot)
on Jun 29, 2012 at 03:33 UTC ( #979037=note: print w/ replies, xml ) Need Help??


in reply to Comparing 2 arrays but ignoring certain patterns

Fixed a few things:

#!/usr/intel/bin/perl use strict; use warnings; my @testlist = qw(ctahci cptcsa0 ctsata:25:seed cptcsa1:50:seed ctsata +_1:25:seed); my @removelist =qw(cptcsa0 ctsata cptcsa1); my $outfile = "./new.list"; my %removehash=map{$_=>1} @removelist; my @newlist=grep !defined( $removehash{ (m/(\w+)/)[0] }), @testlist; # creating new list open (my $OUTFILE, ">",$outfile) or die "Cannot open $outfile for writ +ing:$!\n"; print $OUTFILE "$_\n" foreach (@newlist);
---Output:---
ctahci
ctsata_1:25:seed

Adjust the regular expression to suite your requirements.

             I hope life isn't a big joke, because I don't get it.
                   -SNL


Comment on Re: Comparing 2 arrays but ignoring certain patterns
Download Code
Re^2: Comparing 2 arrays but ignoring certain patterns
by hongping (Novice) on Jun 29, 2012 at 06:53 UTC
    ur script is great, but my @testlist and @removelist may contain more than one word such as:
    ctahci_sip11cs_devslp_deto_exp:50:seed ctahci_sip11cs_devslp_deto_exp2:50:seed
    therefore the code will assume it is same when one word is matching. How to deal with this?
      You will need to test out the conditions you expect to work, and define your problem more clearly.

      I tested the patterns you proposed with my code - it works fine.

      If it does not meet your requirements, as I said in my previous post - feel free to modify the regular expression to work with your requirements.

                   I hope life isn't a big joke, because I don't get it.
                         -SNL

      I don't understand, especially where you say

      ... @removelist may contain more than one word such as:
      ctahci_sip11cs_devslp_deto_exp:50:seed
      ctahci_sip11cs_devslp_deto_exp2:50:seed

      The string  'ctahci_sip11cs_devslp_deto_exp:50:seed' doesn't look like anything appearing in the  @removelist array in your OPed example code. Can you give an example of data for which NetWallah's code fails?

Re^2: Comparing 2 arrays but ignoring certain patterns
by hongping (Novice) on Jul 03, 2012 at 06:18 UTC
    After the several tries. This code just perfect for me. Thanks a lot. =)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://979037]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2014-08-20 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (122 votes), past polls