Code Comments
Programming Forum and web based access to our favorite programming groups.First here's my code:
while (my $ref = $dblist -> fetchrow_arrayref ()) {
$surveyQuestions{question}[$counter]= $ref->[0];
$surveyQuestions{displayType}[$counter]=
$ref->
[1];
$surveyQuestions{saveValue}[$counter]=$r
ef->[2];
#Get Answers:
$ref->[2]=~ s/.*\.//;
$baseColumn=$ref->[2];
@answers=$tbl_info->members ($baseColumn);
$surveyQuestions{answers}[$counter]=@ans
wers;
$counter++;
print @answers; # <--- Prints the answers
correctly
}
...
print " Answers:$surveyQuestions{answers}[$x]\n;
# <--- Prints the
number of answers instead
My problem is that I always get the number of answers instead of the
answers. What am I doing wrong?
Post Follow-up to this messageOn Jun 3, 2005, at 23:56, The Ghost wrote:
> $surveyQuestions{answers}[$counter]=@ans
wers;
> print " Answers:$surveyQuestions{answers}[$x]\n;
# <--- Prints the
> number of answers instead
>
> My problem is that I always get the number of answers instead of the
> answers. What am I doing wrong?
Perl structures can store just scalars. You need to pass an arrayref
instead of an array, for instance this way:
$surveyQuestions{answers}[$counter] = [ @answers ];
In your code @answers is being evaluated in scalar context, hence
giving the number of answers.
See perldsc.
-- fxn
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.