Perl/Shell Knowledge Sharing
Perl Interview Questions and Answers
Saturday, January 15, 2011
perl: grep array against array
my @characteristic = ("LA","SF");
my @info_tony = ("LA","SF","NY");
my %seen = ();
my @union = grep { $seen{ $_ }++ } @characteristic, @info_tony;
if ( @union ) {
print "$_\n" for @union;
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment