Skip to content

Instantly share code, notes, and snippets.

@ggl ggl/
Last active Dec 28, 2015

What would you like to do?
Four ways to match two arays
#!/usr/bin/env perl
# four ways to match two arays
use strict;
use warnings;
use match::smart qw(match);
use Test::Deep;
use Benchmark qw(cmpthese);
my @a = qw(a b c d e);
my @b = qw(a b c d e);
my $array_comp = sub {
my ($xr, $yr) = @_;
return unless @$xr == @$yr;
my $i;
for my $e (@$xr) {
return unless $e eq $yr->[$i++];
return 1;
cmpthese -2, {
smartmatch => sub { @a ~~ @b },
match_smart => sub { match(\@a, \@b) },
eq_deeply => sub { eq_deeply(\@b, \@a) },
array_comp => sub { $array_comp->(\@a, \@b) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.