Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Correction to arrays Q&A answer

by whakka (Hermit)
on Sep 19, 2008 at 15:55 UTC ( [id://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 (Paladin) on Sep 19, 2008 at 20:41 UTC
    Fixed.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found