Update:I cleaned up a redundant subroutine call in my code.

You need to get the information out with a custom sql statement and put it in some kind of data structure if it exists. There are a lot of ways to do this. a quick example.

#!/usr/bin/perl -w use strict; use DBI; #db connect my $driver = 'mysql'; my $database = 'usersdb'; my $dsn = "DBI:$driver:database=$database"; my $dbh = DBI->connect($dsn, undef, undef); my $user ="bob"; my $user_test = user_exists($user); if (defined $user_test){ print "user $user is already in our database"; }else{ #code to insert user } $dbh->disconnect; sub user_exists{ my $id_val = shift; my $statement = "select user_id from users where user_id = $id_val +"; my $ary_ref = $dbh->selectall_arrayref($statement); if (defined $ary_ref->[0]->[0]){ return $ary_ref->[0]->[0]; }else{ return undef; } }

In reply to Re: mySQL with Perl by thunders
in thread mySQL with Perl by skirrow

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.