Re: Comparing hash tables




John W. Krahn napisal(a):
Rem-8 wrote:

OK, so here we go:

The table on the top is right

Now the read data has to be the same as the table because we have text
like this:

instance -01 copy -f0 size 3441
instance -01 copy -f1 size 4321
instance -01 copy -f2 size 3441
instance -01 copy -f3 size 4321
instance -02 copy -f0 size 3441
instance -02 copy -f1 size 4321
instance -02 copy -f2 size 3441
instance -03 copy -f0 size 4321

Now $1 will be 01, 02, 03 and $2 would be 0, 1, 2, 3.
As you see, the copy 3 is missing for instance 02 - that will be a
mistake, because every instance from 01 to 13 has to have copies from 0
to 3. This why I need to compare those values

This should give you some ideas to get you started:


#!/usr/bin/perl
use warnings;
use strict;


my @xx = '01' .. '13';
my @y = '0' .. '3';

my $xx_index = $#xx;
my $y_index = $#y;

while ( <DATA> ) {
next unless /-(\d+)\s+\S+\s+-f(\d+)\s+\S+/;

$y_index = ( $y_index + 1 ) % @y;
$xx_index = ( $xx_index + 1 ) % @xx unless $y_index;

if ( $1 ne $xx[ $xx_index ] || $2 ne $y[ $y_index ] ) {
print "Error: missing entry for xx=$xx[$xx_index] and y=$y[$y_index]\n";
redo;
}
}


__DATA__
instance -01 copy -f0 size 3441
instance -01 copy -f1 size 4321
instance -01 copy -f2 size 3441
instance -01 copy -f3 size 4321
instance -02 copy -f0 size 3441
instance -02 copy -f1 size 4321
instance -02 copy -f2 size 3441
instance -03 copy -f0 size 4321




John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall


Thanks for the replies! It realy helped me!

Cheers!

.