-2
#!/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 值不匹配,所以我知道在某些情况下,值和相应的值不会是它们的值,我只想要这些情况。对此代码有任何解决方法吗?请。这段代码很简单,但不知道为什么它不起作用!!:( :(

4

1 回答 1

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].

于 2013-05-15T17:41:24.003 回答