in reply to Re: any replacements for smartmatch on comparing two arrays
in thread any replacements for smartmatch on comparing two arrays

well guys i am on a shared server whose admin doesn't allow new modules.

  • Comment on Re^2: any replacements for smartmatch on comparing two arrays

Replies are listed 'Best First'.
Re^3: any replacements for smartmatch on comparing two arrays
by CountZero (Bishop) on Sep 24, 2015 at 16:48 UTC
    You can always "inspire" yourself by looking at the source of List::Compare or Data::Compare and then include their code bodily into your script.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

      I just tested this with Data::Compare. To use the Compare function, all that is required is appending the Compare sub contents from the Data::Compare source into the script following this required code (note that both Carp and Scalar::Util have been in core since pre-5.8).

      use warnings; use strict; use Carp; use Scalar::Util; my (%been_there, %handler); print Compare([], [qw(1 2)]);
Re^3: any replacements for smartmatch on comparing two arrays
by Athanasius (Archbishop) on Sep 24, 2015 at 15:57 UTC

    OK, this does the comparison in a single line, using no modules and no explicit loops:

    my $match = @array1 == @array2 && !grep { !$_ } map { $array1[$_] eq $ +array2[$_] } 0 .. $#array1;

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,