che sto cercando di capire questo codice Perl ...numero dispari di elementi in hash anonimo
Se c'è un flusso che funziona, se ci sono 2 o più flussi avverte con un numero dispari di elementi in forma anonima hash. Sembra che restituisca una matrice in quel caso. Come aggiungo correttamente gli elementi dell'array a @streams? Sembra aggiungere correttamente il caso HASH nella clausola if. La cotta della clausola else?
my $x = $viewedProjectDataObj->{streams};
if (ref($x) eq 'HASH') {
push(@streams, $x->{id});
} elsif (ref($x) eq 'ARRAY') {
print "$x\n";
print "@$x\n";
my @array = @$x;
foreach my $obj (@array) {
print "in $obj\n";
print Dumper($obj);
push(@streams, ($obj->{id}));
}
}
print "streamcount " . @streams % 2;
print Dumper(@streams);
my $stream_defect_filter_spec = {
'streamIdList' => @streams,
'includeDefectInstances' => 'true',
'includeHistory' => 'true',
};
my @streamDefects = $WS->get_stream_defects($defectProxy, \@cids, $stream_defect_filter_spec);
print Dumper(@streamDefects);
sto aggiungendo le prossime righe ...
if ($defectSummary->{owner} eq "Various") {
foreach (@streamDefects) {
if (exists($_->{owner})) {
$defectSummary->{owner} = $_->{owner};
last;
}
}
}
my $diref = $streamDefects[0]->{defectInstances};
if ($diref) {
my $defectInstance;
if (ref($diref) eq 'HASH') {
$defectInstance = $diref;
} elsif (ref($diref) eq 'ARRAY') {
$defectInstance = @{$diref}[0];
} else {
die "Unable to handle $diref (".ref($diref).")";
}
Ora gli errori con API
Web ha restituito il codice di errore S: Server: chiamando getStreamDefects: Nessun flusso trovato per nome nullo. $ VAR1 = -1; me Impossibile utilizzare stringa ("-1") come Rif HASH mentre "strict refs" in uso presso la linea 317. xyz-handler.pl
qualche uscita Dumper
$VAR1 = {
'streamIdList' => [
{
'name' => 'asdfasdfadsfasdfa'
},
{
'name' => 'cpp-62bad47d63cfb25e76b29a4801c61d8d'
}
],
'includeDefectInstances' => 'true',
'includeHistory' => 'true'
};
pls rivedere la risposta. ancora il problema –
@DB, ha aggiunto entrambi gli esempi. – jm666