Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: DB search results using DBI...execute

by jamroll (Beadle)
on Mar 04, 2017 at 21:47 UTC ( [id://1183675]=note: print w/replies, xml ) Need Help??


in reply to Re^2: DB search results using DBI...execute
in thread DB search results using DBI...execute

my @results = search_item($dbh, \@users, $st, $sv) . "\n"; is slightly incorrect, btw - and not sure how the "\n" got in there....it's not there in my actual code. so, it should read just: my @results = search_item($dbh, \@users, $st, $sv);

Replies are listed 'Best First'.
Re^4: DB search results using DBI...execute
by poj (Abbot) on Mar 05, 2017 at 08:51 UTC

    Try this simple cgi to show the benefit of using Dumper.

    #!perl # Dumper demo cgi use strict; use Data::Dumper; print "Content-Type: text/html\n\n"; print '<pre>'; my $ref = [ { ID => 'ABC'},{ ID => 'DEF'},{ ID => 'GHI'} ]; print '<h2>$ref</h2>'; print Dumper $ref; print '<hr/>'; my @array = map { $_->{ID} } @$ref; print '<h2>@array</h2>'; print Dumper @array; print '<hr/>'; my @error = @array."\n"; print '<h2>@error</h2>'; print Dumper @error; print '<hr/>';

    Also, note how map could be used to replace this code in search_item()

    my @array = @$resultsRef foreach my $hit (@array) { # $hit is a hash reference. my %hash = %$hit; push @searched, $hash{ID}; }
    poj
      even better though, would be to drop the %hash = %$hit and write the push command as push(@searched, $hash->{ID}); which saves so much typing, and is much more readable and understandable...having to do "my %hit = ..." gets tedious - especially when yer imagination for new var names gets exhausted lol
      haha! yes, yes - quite correct. it's been a long while since I looked at this thread, and I am so very happy that I changed this search_item to reflect how you wrote it. I recoded that routine long ago - so that makes me feel great and feel like i'm on the right track with that, so thank you very much! most cool

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1183675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found