in reply to Re: Extra iteration while fetching 'fetchrow_array' in DBI and standerd way of using DBI
in thread Extra iteration while fetching 'fetchrow_array' in DBI and standerd way of using DBI

($endstore[$ctrend][0], $endstore[$ctrend][1], $endstore[$ctrend][2], $endstore[$ctrend][3], $endstore[$ctrend][4]) = @arr;

can be abbrieviated to

@{$endstore[$ctrend]}[0..3] = @arr[0..3];

If I read the intent correctly, it can be abbrieviated further to

$endstore[$ctrend] = [ @arr ];

Of course, since $ctrend is always being incremented, we simply want

push @endstore, [ @arr ];

Final result:

while (my @arr = $sth2->fetchrow_array() ) { push @endstore, [ @arr ]; my ($field1, $field2, $field3, $field4, $field5) = @arr; $endflag=2; print STDOUT "Field 1: $field1 Field 2: $field2 " . "Field 3: $field3 Field 4: $field4 " . "Field 5: $field5\n"; }

Note that [ @arr ] can't be replaced by \@arr since you'd be pushing multiple references to the same array.

  • Comment on Re^2: Extra iteration while fetching 'fetchrow_array' in DBI and standerd way of using DBI
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: Extra iteration while fetching 'fetchrow_array' in DBI and standerd way of using DBI
by roboticus (Chancellor) on Jun 16, 2007 at 04:16 UTC
    ikegami:

    I thought about simplifying it further, but I didn't want to "go all perlmonks on him". ;^)

    Actually, I was going to go further and try to simplify the endstore assignment, but I wasn't comfortable enough in my perliness to be certain the best way to do it. (I've been doing C++ for a while lately, and it takes my brain a bit to shift gears...)

    --roboticus

    Update: Added hyperlink to quote...

Re^3: Extra iteration while fetching 'fetchrow_array' in DBI and standerd way of using DBI
by cool (Scribe) on Jun 16, 2007 at 12:09 UTC
    Dear ikegami,

    Actually something just opposite I wanted; I wanted monks to go all monks way go all perlmonks on him, but to phrase that in such way was a problem :) To tell you the truth, I have learnt anonymous reference Re^2: create hash names dynamically just 5 days ago and while learing DBI got the opportunity to use that. But after writing/working I knew there must be shorter ways to do that. But it would come to this, I did not have idea. So frankly I am impressed, once again. And to add further to that, would love to be bombarded by samego all perlmonks on him way, all the time.

    Thank you for showering of wisdom.
    Love you all monks :)