Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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"


In reply to Re: DB search results using DBI...execute by huck
in thread DB search results using DBI...execute by jamroll

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-26 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found