Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

hashes and arrarys
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?


Report this thread to moderator Post Follow-up to this message
Old Post
The Ghost
06-04-05 01:55 AM


Re: hashes and arrarys
On 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


Report this thread to moderator Post Follow-up to this message
Old Post
Xavier Noria
06-04-05 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:48 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.