kevin liu schrieb:
        --------------------------------------------------------
        But this algorithm takes a long time to compare, could you please
help to improve this piece of
code to less the time needed?

        Thanks in advance.

I don't know if it's faster, but you can also use the smart-match operator of perl5.10.0.

use feature ':5.10';
use strict;
use warnings;

my @a=qw/A B C/;
my @b=qw/A B C/;
my @c=qw/C A B/;

say "\...@a=\@b" if @a ~~ @b; # True
say "\...@a=\@c" if @a ~~ @c; # Won't work this way, wrong order

my %match;
@mat...@c}=(1) x @c;
say "\...@a=\@c" if @a ~~ %match; # But this works.

Or if you don't have perl5.10.0

print "\...@c=\@a\n" if @{...@match{@a}]} == scalar(@a) ; #Not perl5.10.0 way

Does anyone have a better idea how to force list context in the last line?

scalar(@mat...@a}) returns 1, the first element, not 3


Marc "Maluku" Lucksch

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to