For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2006 > Array::Compare List Context









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Array::Compare List Context
Chris

2006-03-27, 9:57 pm

Can anyone help me with how to call Array::Compare in a list context?

> #!/usr/bin/perl -w
> use strict;
> use Array::Compare;
> use Data::Dumper;
>
>
>
> my @first = ("1" , "3" , "5" , "7");
> my @second = ("2", "3" , "5" , "6");
>
> my $comp = Array::Compare->new(DefFull => 1); # 0 = Simple 1 = Full
> $comp->compare(\@second, \@first);
>
> # foreach (keys %HASH) {
> # print "$_ => $HASH{$_}\n";
> #}
>
> # print $Array::Compare::diffs;
>
> print($comp);


The above returns Array::Compare=HASH(0x18d7e30). Stepping through
debugger, I can see that it picks up the @diffs at 1 and 3 before
Destroy(). I simplistically tried my @comp = and print @comp;, but
sense that I'm actually trying to get @diffs (within the module).

Overall, my goal is to compare an array that has a mix of text and regex
abstractions with another array of text.
This approach didn't work:

#!/usr/bin/perl -w
use strict;
use Array::Compare;
use Data::Dumper;

my $pattern = '~m/\d/';

my @first = ("1" , "$pattern" , "5" , "6");
my @second = ("2", "3" , "5" , "6");

my $comp = Array::Compare->new(DefFull => 1); # 0 = Simple 1 = Full
$comp->compare(\@second, \@first);


# print $Array::Compare::diffs;

print($comp);

Which returns Array::Compare=HASH(0x18d7e9c), picking up that 0 and 1
are different (as seen in debugger), but not comparing the pattern to 3.
I was hoping to sn a regex comparison into the array 1 eq array 2
with the ~. That didn't work.

I'm probably fishing in the wrong direction, but still don't know enough
perl to help myself.

Thanks,

Chris

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com