Before I point to the problem here, let me point out that you are trying 
to use symbolic references which will severely decrease the readability 
of your code.

<soapbox>
I personally believe that symbolic references are one of the many forms 
of evil perl which, while appearing elegant, merely lure you  into the 
mire of obfuscation.  If you need a named list of arrays you should 
probably be using a hash.  The keys can be generated in the same way but 
are bound to the data structure (ie, you can find out what they are with 
keys() instead of having to know the secret formula).  Stay away from 
symbolic references, they don't work with 'use strict;' anyway.  That 
should tell you something.
</soapbox>

So what's happening here is that you assign a string to the lexical 
variable $arrayname and then *overwrite* this with the hash arrayname.  
You don't dereference the symbolic reference so it uses the variable 
name 'arrayname' instead of the dynamic name you generated.   If you 
just add another '$' in front, it should work the way want.  You might 
want to do '${$arrayname}{$column[0]}' to at least alert the reader of 
the code that something weird is going on here.

Good Luck,
Peter C.


On Monday, December 31, 2001, at 01:01 PM, Andrew Koebrick wrote:

> I am trying to build up associative arrays using a looping draw from a 
> database.  I would like to end up with one or more arrays(depending on 
> number of elements in the @Dataset) named %sub0, %sub1, %sub2... and so 
> on.  I need to keep these arrays around for latter manipulation.
>
> What I have now is:
>
> $c=0;
> foreach (@Datasets){
>      my $SQL = "select year,value from data where trend like 
> '%$Datasets[$c]%' order by year";
>      my $arrayname = "\$sub$c";
>      my $cursor = $dbh->prepare($SQL);
>       $cursor->execute;
>       while(@columns = $cursor->fetchrow){
>               $arrayname{$columns[0]} = $columns[1];     #FAILED LEFT SIDE 
> INTERPOLATION
>                                 } # end while assignment
>      $c++;
>                                     }
>
> However, what obviously is happening is that $arrayname{columns[0]} = 
> $columns[1] is sticking the values into an array called "$arrayname" 
> rather than interpolating back to "$sub0" (or "sub1"... depending on 
> what loop we are in).  I've tried various conbinations of quotation 
> marks and eval statements to try to make this work with no luck.  Can 
> this be done?  If not, is there a standard workaround?
>
> Many thanks for any assistance.
>
> Andrew Koebrick
> Web Coordinator/Librarian
> MN-Planning (Office of Strategic and Long Range Planning)
> 658 Cedar St., Suite 300
> St. Paul, MN 55155
>
> 651-296-4156 phone
> 651-296-3698 fax
>
> www.mnplan.state.mn.us
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to