in reply to Re: use simple scalar names to point to specific array elements
in thread use simple scalar names to point to specific array elements
I was trying to create only one list within the code with all these column names defined. Then, if someone needs to enter a new column, appending to the list could then be used to create the proper 'SELECT' statement, and also modify the way the result was read.
i.e. What I don't want:
because then the next guy to maintain my code might goof up when they have to add (or move around) columns.my $query = "SELECT abc def ghi jkl ....."; ... set up database stuff ... ($abc, $def, $ghi, $jkl ...) = @array;
So I set up an array with all the column names, and create the query (which is complex) using the column names.
So far so good, I got that far. But now when I want to be able to create a list (or array) that can read in the result, and create new variables based on the list of columns.
So, I decided to make things difficult for myself, and was fartin' around trying to construct some code that could use the pre-existing list of column names to construct the array assignment.
Something like (I haven't tried this, i'm just trying to brain storm...)
I'm guessing that "use strict vars" is going to be upset when I try to access $abc;map {$_='$'.$_} (@var_list=@col_list) join (",",@var_list); (eval "$var_list") = @array;
However, before I started with that, I just sorta fell back into some of the joys of FORTRAN (yes fortran can be fun too).
In my previous fortran code, one could read a line from a text file, using a single string or array. Then, use the individual fields as required. If the format of the input line changed, the only thing that needs to be changed is the equivalence statement.
Any thoughts?
I could always just hard code the variable and column names and be done with it, but I don't wanna. I can be very stubborn at times.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: use simple scalar names to point to specific array elements
by diotalevi (Canon) on Dec 05, 2003 at 21:14 UTC | |
by Sandy (Curate) on Dec 05, 2003 at 21:24 UTC |