Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Deleting elements of one list using another

by jwkrahn (Monsignor)
on Aug 02, 2012 at 09:45 UTC ( #984993=note: print w/replies, xml ) Need Help??

in reply to Deleting elements of one list using another

$ perl -le' use Data::Dumper; my @arr1 = ( "John, ABC, 42", "Jane, XYZ, 34", "Jessica, GHI, 21" ); my @arr2 = ( "ABC", "XYZ" ); my $pattern = join "|", @arr2; my @arr3 = grep /$pattern/, @arr1; print Dumper \@arr3; ' $VAR1 = [ 'John, ABC, 42', 'Jane, XYZ, 34' ];

Replies are listed 'Best First'.
Re^2: Deleting elements of one list using another
by suaveant (Parson) on Aug 02, 2012 at 13:39 UTC
    Right idea but you aren't using anything to anchor the pattern, so you would also match 'JohnABC, CDE, 14'
    @arr1 = ("0000007 | John | ABC.txt | 42","0000014 | Jane | XYZ.txt | 3 +4","0000017 | Jessica | GHI.txt | 21", etc); @arr2 = ('0000007', '0000014'); my $re = join('|',@arr2); my @arr3 = grep /^(?:$re)\s/, @arr1; print join("\n",@arr3),"\n";

                    - Ant
                    - Some of my best work - (1 2 3)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://984993]
[shmem]: No, not coincidence - prejudice and bias
[shmem]: your scanner is pre-loaded ;-)
[shmem]: anyways, do as is your wont. I won't fight western hypocresy anymore - for today. Let's call that a day, and done.
[erix]: yeah, scanning pre-loaded. I wouldn't have it any other way. As I say, my attention is a rare commodity, jealously guarded.
[erix]: ok, ok. happy pipe-dreams :P

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-03-19 21:12 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.