Perl cheatsheet
This is a regularly modified post which holds all of the small bits and tips that don’t warrant their own post. If there is a group of related tips that pass a critical mass, they will be spun out into their own post, and a placeholder will remain here.
Comparing two data structures
sub elementwise_eq {
my ($xref, $yref) = @_;
return unless @$xref == @$yref;
my $it = each_arrayref($xref, $yref);
while ( my ($x, $y) = $it->() ) {
return unless $x eq $y;
}
return 1;
}
An alternative to this is to use Test::More
use Test::More tests => 2;
is_deeply(\@array1, \@srray2, 'Checking arrays are the same');
is_deeply(\%hash1, \%hash2, 'Checking hashes are the same');