in reply to to pick the common element in the array
(code can probably be golfed down.) :-)#!/usr/bin/perl use warnings; use strict; my @array1=('a','2','3','2'); my @array2=('1','2','3','2'); my %in_array2 = map { $_ => 1 } @array2; my @array3 = grep { $in_array2{$_} } @array1; print "common @array3\n"; my %seen; my @unique = grep{!$seen{$_}++} @array3; print "unique @unique\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: to pick the common element in the array
by Ksonar (Initiate) on Aug 28, 2017 at 07:48 UTC | |
by zentara (Cardinal) on Aug 28, 2017 at 12:01 UTC | |
|
Re^2: to pick the common element in the array
by Anonymous Monk on Feb 20, 2014 at 18:51 UTC | |
by zentara (Cardinal) on Feb 21, 2014 at 11:37 UTC | |
|
Re^2: to pick the common element in the array
by Anonymous Monk on Mar 13, 2009 at 12:48 UTC | |
by zentara (Cardinal) on Mar 13, 2009 at 19:16 UTC |