두 개의 해시 테이블과 일치해야하지만 해당 키가 일치하지 않습니다. 그래서 나는 각 해시 테이블에 도달하고 값으로 매치한다. 그래서 코드를하지 않는 다음 작품 :펄에서 해시 테이블에 도달
sub _findHashElt
{
my ($this, $hashTarget) = @_;
my $isFound = 0;
my $isItemFound = 1;
my $isHashFound = 0;
my $result = undef;
my %hashTable=%{$this->{templates}};
my %hashTargetHash=%{$hashTarget};
my %hashSubTable = undef;
while ( (my ($key, $value) = each(%hashTable))
and ($isFound == 0 ))
{
$isItemFound = 1;
$isHashFound = 0;
####################################
# DOES NOT WORK
%hashSubTable = %{$hashTable{$key}};
####################################
while ( (my ($subKey, $subValue) = each(%hashTargetHash))
and ($isItemFound == 1 ))
{
$isItemFound = 0;
while ( (my ($subTableKey, $subtableValue) = each(%hashSubTable))
and ($isItemFound == 0 ))
{
$isHashFound = 1;
$isItemFound = ($subValue eq $subtableValue) ? 1 : 0;
}
}
if ($isItemFound == 1 && $isHashFound == 1) {
$isFound = 1;
$result = $key;
}
}
return $result;
}
그리고 다음 코드는 작동 :
sub _findHashElt
{
my ($this, $hashTarget) = @_;
my $isFound = 0;
my $isItemFound = 1;
my $isHashFound = 0;
my $result = undef;
my %hashTable=%{$this->{templates}};
my %hashTargetHash=%{$hashTarget};
my %hashSubTable = undef;
while ( (my ($key, $value) = each(%hashTable))
and ($isFound == 0 ))
{
$isItemFound = 1;
$isHashFound = 0;
while ( (my ($subKey, $subValue) = each(%hashTargetHash))
and ($isItemFound == 1 ))
{
####################################
# WORK
%hashSubTable = %{$hashTable{$key}};
####################################
$isItemFound = 0;
while ( (my ($subTableKey, $subtableValue) = each(%hashSubTable))
and ($isItemFound == 0 ))
{
$isHashFound = 1;
$isItemFound = ($subValue eq $subtableValue) ? 1 : 0;
}
}
if ($isItemFound == 1 && $isHashFound == 1) {
$isFound = 1;
$result = $key;
}
}
return $result;
}
사람은 문제가 무엇인지하시기 바랍니다이며, 말해 줄 수주십시오?
EDIT
첫째 ...
편집 제 경우
#############################################
################# TEST PART #################
#############################################
my $this = {"templates" => {}};
my $example = {'key0' => {'key00' => 'test00', 'key01' => 'test01', 'key02' => '0', 'key03' => 'test03'},
'key1' => {'key00' => 'test10', 'key01' => 'test11', 'key02' => '1', 'key03' => 'test13'},
'key2' => {'key00' => 'test20', 'key01' => 'test21', 'key02' => '1', 'key03' => 'test23'},
'key3' => {'key00' => 'test30', 'key01' => 'test31', 'key02' => '0', 'key03' => 'test33'}};
my $expected = {'key00' => 'test00', 'key01' => 'test01', 'key02' => '0', 'key03' => 'test03'};
$this->{templates}=$example;
_findHashElt($this, \%expected);
키가 발견되지 않았으며, 두 번째의 키가 밝혀졌다 사례 :
$ perl myTest.pl
Key not found
두 번째 경우 :
$ perl myTest.pl
Key found
{
key01 : test01
key00 : test00
key03 : test03
key02 : 0
}
편집
또 한가지, 내가 그것을
$ perl --version
This is perl, v5.10.1 (*) built for i686-cygwin-thread-multi-64int
(with 13 registered patches, see perl -V for more detail)
일반적으로 문제를 최소 버전으로 낮추는 것이 가장 좋습니다. –
나는 최소한의 버전으로 내 문제를 종결하는 법을 모르겠다. 하지만 전체 예제를 추가 할 수 있습니다. 도움이 될 수 있습니다. –
'작동하지 않는다 '는 것은 무엇을 의미합니까? 입력 및 예상 출력에 대한 샘플 데이터를 제공해 주시겠습니까? –