Thank you for responding and offering help. here's the code that doesn't work (in all of its ugliness.) and that is followed by what I think is just a cleaner version that DOES work??? I don't know why (could it be the SWITCH or the way I get the arguments to the subroutine???
use Switch; use DBI; sub rec_exists; my (@retRows, @row, @tmp, $retRecs); while ($line = <>) { chomp($line); if ($line eq "q") { goto Exit; } else { $retRecs = rec_exists($line,\@retRows); } $tmp = @retRows[0]; @row = @$tmp; ($nKey, $fN, $lN, $bN, $hN, $mN) = @row; print "$nKey,$fN, $lN, $bN, $hN, $mN\n"; } Exit: exit(); sub rec_exists { my ($searchType,$searchParm,$retArrayRef) = split(/,/,@_[0]); my $dbh = DBI->connect("DBI:mysql:database=aaaaas;host=localhost", +"bbbbbb","cccccccccc",{'RaiseError' => 1}); my ($found, @row, @rows, $nKey, $sth); $rowRef; @rows = (); switch($searchType) { case "1" { # search using the nKey $nKey = $searchParm; chomp($nKey); $nKey =~ s/^\s+//; $nKey =~ s/\s+$//; $sth = $dbh->prepare("Select * from sContacts where nKey like + '$nKey%'"); $sth->execute(); $found = 0; while ( $rowRef = $sth->fetchrow_arrayref ){ $retArrayRef->[$found] = [ @$rowRef ]; $found++; } } } $sth->finish; $dbh->disconnect; return $found; }
====================== Now here's the stuff that does work
use Switch; use DBI; my (@retRows,$retRecs, $searchKey); $searchKey = 'marcC'; $retRecs = test_exists($searchKey,\@retRows); print "returned $retRecs\n"; $tmp = @retRows[0]; print "@$tmp\n"; exit(); sub test_exists { my ($searchKey, $retRowsRef) = @_; my ($retArrayRef, $found); my $dbh = DBI->connect("DBI:mysql:database=aaaaa;host=localhost"," +bbbbbb","ccccccccc",{'RaiseError' => 1}); my $sth = $dbh->prepare("Select * from sContacts where nKey like +'$searchKey%'"); $sth->execute(); $found = 0; while ( $retArrayRef = $sth->fetchrow_arrayref ){ $retRowsRef->[$found] = [ @$retArrayRef ]; $found++; } $sth->finish; $dbh->disconnect; return $found; }

In reply to Re^2: keep database records after select by marc724
in thread keep database records after select by marc724

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.