Sonika Sachdeva wrote:
I have Hash of array. I want to compare the array values within the hash.
How can it be done?
if ($eline =~ /$pattern/ ) {
$eline =~ /(.*)\"(\w+)\s(.*)\?(.*)\"/ ; my $uniq=$1; my
$url=$4;
chomp($uniq);chomp($url);
my @var= ( split("&",$url) );
foreach my $k (@var) {
@value = split("=",$k);
if ( $value[0] eq "package_guid" ) { push
@{$VAR{$uniq}},@value; }
if ( $value[0] eq "deployment_id" ) { push
@{$VAR{$uniq}},@value; }
}
OK, is this inside an input loop? If so, maybe you would want to move
your comparison outside of it. (If you're not inside a loop, %VAR has
only one value in it.)
foreach my $x (keys %VAR) {
$VAR{$x}[0] has two different values: 'package_guid' and 'deployment_id'
If you are comparing only package_guid, then:
next unless $VAR{$x}[0] eq 'package_guid';
foreach my $y (keys %VAR) {
Again:
next unless $VAR{$y}[0] eq 'package_guid';
< Comparison code if 2 entries have same
pacakge_guid
OK, this is only a top-level compare:
my $is_eq = 0;
# Are the size of the arrays the same?
if( @{$VAR{$x}} == @{$VAR{$y}} ){
$is_eq = 1;
# scan the elements
for my $i ( 1 .. $#{$VAR{$x}} ){
if( $VAR{$x}[$i] ne $VAR{$y}[$i] ){
$is_eq = 0;
last;
}
}
}
# $is_eq is TRUE if the arrays are eq
}
}
}
plz suggest.
Thanks,
--
Just my 0.00000002 million dollars worth,
--- Shawn
"For the things we have to learn before we can do them,
we learn by doing them."
Aristotle
"The man who sets out to carry a cat by its tail learns something that
will always be useful and which will never grow dim or doubtful."
Mark Twain
"Believe in the Divine, but paddle away from the rocks."
Hindu Proverb
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>