나는이 특정 코드를 사용하여 5.10 (작동과 같은 작동)을 사용하지만 5.8에서 작동하도록해야합니다. 5.8에 이것을 쓰는 또 다른 방법은 무엇입니까? 선호하는 방법/기법?5.8과 함께 사용하기 위해 perl switch-like 문을 코드하는 방법
for my $detail ($Details1, $Details2) {
for (keys %$detail) {
when ('file') {
print " File: $detail->{file}{path}\n";
print "Bytes: $detail->{file}{size}\n";
}
when ('directory') {
given (ref $result->{directory}) {
when ('ARRAY') {
for my $entry (@{$detail->{directory}}) {
print "Directory: $entry->{path}\n";
}
}
when ('HASH') {
print "Directory: $detail->{directory}{path}\n";
}
}
}
}
}
감사합니다. 반환 할 데이터가없는 경우 빈 문자열에 대해'ref'도 검사 할 수 있습니까? – cjd143SD
'if (! $ result -> {directory}) {...}'또는'if ($ result -> {directory}) eq '') {..}'는 빈 문자열과 일치합니다. – Zaid