【发布时间】:2013-12-30 05:16:31
【问题描述】:
我遇到了一个相当奇怪的问题。我只是想通过循环遍历存储输入名称的数组以及与该名称关联的注释来显示用户输入的 cmets。
#Check through each name
for ( my $i = 0; $i < scalar @$namesRef; $i++ )
{
#Display the comment to the user
print @$namesRef[$i].": ".@$commentsRef[$i], p;
}
在显示 cmets 的页面上,而不是像“John:comment”那样显示它们,而是像“Johncomment:”那样显示它。此外,',p' 不包括在内,因此下一条评论不会换行。
我会放一张图片来更好地显示问题所在,但我还没有足够的代表:/
编辑:@ 符号在那里,因为这些是对该子例程之外的数组的引用。
编辑:初始数组在此子例程中声明。
子构建表单 { 我的 $form = shift; #检查哪个按钮被按下。
my $daysOld = 0; #Holds how many days old the user is.
my $commentErrors = 0;
my @names = ();
my @comments =(); #Array to store the user's comments.
my @errorMessages =(); #Array to store the error messages for the current form.
下面是注释表单的子程序调用的地方:
elsif ( $form == 3 )
{
&readComments(\@comments, \@names, \@errorMessages); #Read in the comments.
#Initial build - Can't have any errors.
&build3(\@comments,\@names, \@errorMessages, $commentErrors, param('name'), param('comment'));
}
elsif ( $form == 4 )
{
$commentErrors = &commentFormErrorCheck( param('name'), param('comment'), \@errorMessages ); #Check for an errors.
&build3(\@comments,\@names, \@errorMessages, $commentErrors, param('name'), param('comment'));
}
【问题讨论】:
-
在这种情况下,您的子调用之前不需要
&。