in reply to DB search results using DBI...execute
resultuse 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; }
First, $#arr returns the index of the last element, not the count.$#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>
Edit: added "index of the" to "returns the index of the last element"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DB search results using DBI...execute
by jamroll (Beadle) on Mar 04, 2017 at 21:49 UTC | |
|
Re^2: DB search results using DBI...execute
by jamroll (Beadle) on Mar 04, 2017 at 21:55 UTC | |
by huck (Prior) on Mar 04, 2017 at 22:02 UTC | |
by jamroll (Beadle) on Mar 04, 2017 at 22:19 UTC | |
by huck (Prior) on Mar 04, 2017 at 22:42 UTC |