在比较基于键的哈希值时,参数不是数字错误

时间:2013-05-15 17:34:34

标签: perl hash

#!/usr/bin/perl
use strict;
use Data::Dumper;
use warnings;
my @mdsum;

open (IN1,"$ARGV[0]") || die "counldn't open";
open (MYFILE, '>>md5sum-problem.txt');
open (IN2, "mdsumfile.txt");
my %knomexl=();
my %knomemdsum = ();
my @arrfile ;
my $tempkey ;
my $tempval ;
my @values ;
my $val;
my $i;
my @newarra;
my $testxl ;
my $testmdsum;
while(<IN1>){
    next if /barcode/;
    @arrfile = split('\t', $_);
    $knomexl{$arrfile[0]} = $arrfile[2];
}

while(<IN2>){
    chomp $_;
    @newarra = split(/ {1,}/, $_);
    $tempval = $newarra[0];
    $tempkey = $newarra[1];
    $tempkey=~ s/\t*$//g;
    $tempval=~ s/\s*$//g;
    $tempkey=~s/.tar.gz//g;
    $knomemdsum{$tempkey} = $tempval;
}

@values = keys %knomexl;

foreach $i(@values){
    $testxl = $knomexl{$values[$i]};
    print $testxl."\n";
    $testmdsum = $knomemdsum{$values[$i]};
    print $testmdsum."\n";

    if ( $testxl ne $testmdsum ) {
        if ($testxl ne ""){
            print MYFILE "Files hasving md5sum issue $i\n";
        }
    }
}
close (MYFILE);

我有两个文件,一个都有文件名和Mdsum值,我需要检查所有文件的md5sum值不匹配,所以我理解在某些情况下,值和相应的值不是他们的,我想要那些案例只要。有关此代码的任何解决方法吗?请。这段代码非常简单但不知道为什么它不起作用!! :( :(

1 个答案:

答案 0 :(得分:1)

 @values = keys %knomexl;

     foreach $i(@values){
        #print Dumper $knomexl{$values[$i]};
        $testxl = $knomexl{$i};
        print $testxl."\n";
        $testmdsum = $knomemdsum{$i};
        print $testmdsum."\n";

$i@values的元素,因为foreach而非索引,因此您不应使用$values[$i]