On May 27, 9:00 pm, [EMAIL PROTECTED] (Brian) wrote:
> Hi All-
> I am trudging through some DBI, XML, etc.. I had a problem and was
> baffled by how to get at array elements out of a series of pushed
> array refs. But, by simplifying the problem, I found that the syntax I
> used was in error. here is the small sample, already debugged. Hope
> this helps someone...
>
> #!/usr/bin/perl
>
> my @tRespsA;
>
> my @fieldList = ( "one", "two", "three", "four" );
> my @r1 = ( 1, 2, 3, 4 );
> my @r2 = ( 13, 14, 15, 16 );
> my @r3 = ( 23, 24, 25, 26 );
>
> push @tRespsA, [EMAIL PROTECTED];
> push @tRespsA, [EMAIL PROTECTED];
> push @tRespsA, [EMAIL PROTECTED];
>
> foreach my $tRowRef ( @tRespsA ) {
> my $tCnt=0;
> foreach my $tFld (@fieldList) {
> #if ( $tRowRef->[ $tCnt] eq "") { next; }
> print $tFld . "='" . $tRowRef->[ $tCnt++ ] . "' \r";
> }
> }
ok... a few things..
use strict and warnings is fine.. this was a small sample, perhaps
allthe more important to include, actually, so you are right there...
my variable names end with A for array and H for hash, start with a
lower case t if they are used locally as temp variables, as in being
written over each time through a loop. But this isn't a real program,
so there isn't that much detail. In fact, I'd say that starting
variable name s with array again and again is very hard to read.
Resp is short for responses. These aren't actually static arrays, they
come from iterating over the arrays returned by a DBI execute(). this
is simplified for purposes of explanation. The reason for the
construct is that those are names of fields used in formulating the
Query string.
var names rows and cols is fine...
yes, I come from C
yes, I have read all of those perl doc pages. You perl folks like to
refer to whose pages a lot Paul, but in many cases they are not very
well written as manuals [this is provably true] However, to give
credit where credit is due, they are often full of interesting
tidbits, and they do exist, so a lot of people have obviously tried to
do a lot of explaining. ..and yes, I can make mistakes in the syntax,
even though I have read through those. Practice makes perfect.
I do appreciate the responses, as I don't really have anyone else to
ask in my environment.
thank you for that
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/