Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Correction to arrays Q&A answer

by whakka (Hermit)
on Sep 19, 2008 at 15:55 UTC ( #712540=monkdiscuss: print w/replies, xml ) Need Help??

I was looking for a solution in the Q&A section that would remove the elements in @B from @A, returning @C. I happened upon the exact question as mine, however one of the answers supplied (dragonchild's) was the opposite of what was wanted and I think whoever is in charge of this should substitute it with the following:

#!perl! -w use strict; use Data::Dumper; my @A = ( 'yahoo.com', 'altavista.com', 'yahoo.com/index.html' ); my @B = ( 'yahoo.com', 'webcrawler.com' ); # The task: make a @C such that @C = ( 'altavista.com' ) # dragonchild's solution: my @C = map { my $x = $_; grep { $x =~ /\Q$_/i } @B } @A; # produces ( 'yahoo.com', 'yahoo.com' ) # proper solution: my @D = grep { my $x = $_; my @matches = grep { $x =~ /\Q$_/i } @B; ! @matches } @A; print Dumper [ \@A, \@B, \@C, \@D ];

Thanks otherwise to dragonchild who has provided many a useful solution to monks like me learning Perl, I'm sure this was just a hasty mental oversight.

Replies are listed 'Best First'.
Re: Correction to arrays Q&A answer
by jdporter (Canon) on Sep 19, 2008 at 20:41 UTC
    Fixed.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2021-05-10 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (108 votes). Check out past polls.

    Notices?