in reply to Finding Mismatches
(note the initial "#!")#!/usr/bin/perl -w use strict;
You have a $AoA[$x1][$y1] in there, but I think this should either be "RAM" or "RAM1" instead of "AoA".
Pushing values of $y1 onto a @shyam array seems pointless -- if you want to keep track of where the mismatches are, you probably want to save $x1 as well as $y1.
You seem to be building an array of hashes in @inde, but each hash only has one key/value pair, with "$y1" as the hash key. Are you planning on adding more key/value things later? If not, you might as well be pushing plain old strings onto a plain old array. (Maybe you really want "inde" to be a HoH, keyed by $x1 and $y1 ?)
It's not clear what sort of result you really want as your output, and you didn't provide any sample input, so I'm not sure what else to say about the code, except that it could be written in a way that would be easier to read (and you can probably use sprintf to get the string format that you want for @inde):
If I were looking for diffs between a couple of 2-D arrays, that sort of how I would do it, I think.# ... after declaring and loading values into @RAM and @RAM1... my %inde; my $rownum = 0; for my $row ( @RAM ) { my $row1 = $RAM1[$rownum]; my $colnum = 0; for my $col ( @$row ) { if ( $col ne $row1->[$colnum] ) { printf( "Mismatch at row %d col %d: RAM=%s vs. RAM1=%s\n" +, $rownum, $colnum, $col, $row1->[$colnum] ); $inde{$rownum}{$colnum} = sprintf( "%17s | %-17s", $col, $ +row1->[$colnum] ); } $colnum++; } $rownum++; } # do something with %inde...
|
|---|