현재 Perl을 사용하여 접미어 트리를 구현하려고하지만 트리 함수에 대한 참조를 설정하려고 할 때 참조 위치가 설정되지 않은 경우 주소를 전달하면 문자열을 통해 문자열의 텍스트와 해시 테이블의 위치를 비교하면 서로 다릅니다. 어떤 도움을 주셔서 감사합니다!Refrence로 해시 테이블을 전달하는 방법 Perl
\%treeRoot, $count = @_;
는 기본적으로, 당신은 당신의 참조를 할당해야합니다 :
use strict;
use warnings;
use Data::Dumper;
my $count = 0;
my $str; # holds the complete string
my %root;
# takes in all lines of code
open(IN, '<:encoding(UTF-8)', $ARGV[0]) or die "Could not open file '$ARGV[0]' $!\n";
while (<IN>) {
chomp;
# concatinates with string
$str .= $_;
}
# closes input
close(IN);
#length of input string
my $l_size = length($str) - 1;
#recursively makes
sub tree {
#recursive root
my %treeRoot;
#checking incomming data
print "1 ".Dumper(\@_)."\n";
#checking incomming data
print "2 ".Dumper(\%root)."\n";
#attempts to set tree's refrence
\%treeRoot, $count = @_;
#checking incomming data
print "3 ".Dumper(\%root)."\n";
#checking incomming data
print "4 ".$count."\n";
#leaf for each node
my %leaf;
for (my $i = 0; $i < $l_size; $i++) {
#creates alphabet tree
$treeRoot { substr($str, $i, 1) } = %leaf;
}
#checking incomming data
print "5 ".Dumper(\%root)."\n";
while ($count > 0) {
#checking incomming data
print "loop 6 ".Dumper(\%root)."\n";
$count--;
#checking incomming data
print "loop 7 ".$count."\n";
#recursion not implamented yet
#tree(\$treeRoot{'a'}, $count);
}
}
tree(\%root, 2);
#print Dumper(\%root);
완벽하게 작동했습니다. 정말 고맙습니다! –
@anon 당신을 진심으로 환영합니다. – TLP