Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Comparing 2 arrays but ignoring certain patterns

by Kenosis (Priest)
on Jun 29, 2012 at 03:46 UTC ( #979038=note: print w/ replies, xml ) Need Help??


in reply to Comparing 2 arrays but ignoring certain patterns

Omit building the hash and try the following grep that uses smart matching:

@newlist = grep !((split /:/)[0] ~~ @removelist), @testlist;

Output:

ctahci ctsata_1:25:seed

Update:

NetWallah provided excellent fixes for your code, and it generates your desired output. You may still, however, use the above grep that doesn't use a hash.


Comment on Re: Comparing 2 arrays but ignoring certain patterns
Select or Download Code
Re^2: Comparing 2 arrays but ignoring certain patterns
by hongping (Novice) on Jun 29, 2012 at 07:12 UTC
    this is no working. syntax error at "]~"
      The smart match operator ( ~~ ) was introduced in perl-5.10, so you'll need perl newer than 5.10 if you want to try it
        is there any other way to do it?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-08-31 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls