in reply to Comparing two arrays (was: any smart ideas??:)
Prints output:use strict; my @a=qw(a b c d); my @b=qw(b a e f); # this does exactly what your pair of 'for' loops # did... my @m = map { my $x = $_; grep { /^$x$/ } @b; } @a; print @m; print "\n";
ab
This time, I'm using a hash to keep count of number of tiems a value is found in both arrays. For any value that's been counted more than once, I dump it into the @m array.use strict; my @a=qw(a b c d); my @b=qw(b a e f); my %h; my @m = map {$h{$_}++ ? $_ : ()} (@a, @b); print @m; print "\n";
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}
|
|---|