http://qs1969.pair.com?node_id=1183674


in reply to DB search results using DBI...execute

use strict; use warnings; use Data::Dumper; my @arr=({a=>1,b=>2},{a=>3,b=>4},{a=>5,b=>6}); print '$#arr :'.$#arr."\n"; print 'scalar(@arr):'.scalar(@arr)."\n"; print Dumper \@arr; my @results = rvar('hash') . "\n"; print Dumper \@results; print "Number of array elements: <b>" . @results . "</b><br>\n"; my @results2 = rvar('arr') . "\n"; print Dumper \@results2; print "Number of array elements: <b>" . @results2 . "</b><br>\n"; sub rvar { my $mode=shift; my @arr=({a=>1,b=>2},{a=>3,b=>4},{a=>5,b=>6}); if ($#arr eq 2) {print "text eq works but weird\n"; } if ($mode eq 'hash') { my $hashRef = $arr[0]; return $hashRef; } elsif ($mode eq 'arr') { my $arrayRef = \@arr; return $arrayRef; } return 0; }
result
$#arr :2 scalar(@arr):3 $VAR1 = [ { 'b' => 2, 'a' => 1 }, { 'b' => 4, 'a' => 3 }, { 'a' => 5, 'b' => 6 } ]; text eq works but weird $VAR1 = [ 'HASH(0x3f7f2c) ' ]; Number of array elements: <b>1</b><br> text eq works but weird $VAR1 = [ 'ARRAY(0xb321bc) ' ]; Number of array elements: <b>1</b><br>
First, $#arr returns the index of the last element, not the count.
Second all you ever return from sql_execute is a scalar, it may be a hashref, or a arrayref, or a number but it is always a scalar.
Third, in my @results = search_item($dbh, \@users, $st, $sv) . "\n"; you force scalar mode with the . for concatenation, and the "\n" gets placed into the @results array appended to scalar result as its only item.
Fourth, you never showed us search_item so i am just sortof guessing but if search_item actualy did return an array the size of the array would be concatenated with the "\n" since scalar context was forced

Edit: added "index of the" to "returns the index of the last element"