だから、私はPerlが初めてです。再帰サブルーチンを作成しようとしています。ロジックは単純に見えます:
sub directory_tree
{
my $sth = $dbh->prepare("
SELECT id, org_id, name
FROM media_directories
WHERE
org_id = ?
AND parent = ?
AND bucket = ?
");
$sth->bind_param(1, $_[0]);
$sth->bind_param(2, $_[1]);
$sth->bind_param(3, 'mfsermons.myflock2.com');
$sth->execute;
$result = '';
while(my($id, $org_id, $name) = $sth->fetchrow_array())
{
$result .= "<option value='$id'>$name</option>"; #377
$result .= directory_tree($org_id, $id); #378
}
return $result;
}
$directory_tree = '<select name="folder">';
$directory_tree .= directory_tree($churchid, 0);
$directory_tree .= '</select>';
377 行目以降を$result
出力すると期待値と等しいのに、378 行目以降を出力すると何も表示されないのはなぜですか? .= 演算子は関数を再度実行してから、値に追加するべきではありませんか?
私の推測では、Perl には理解できないスコープの問題があり、特に$result
. しかし、私の人生では、何が悪いのかわからず、どこを見ればいいのかまったくわかりません!
エラー報告、致命的、および警告をオンにすると、何も返されません。私が行方不明になっている可能性があるのは何が間違っているのでしょうか?