in reply to Re^3: accessing values in hash
in thread accessing values in hash

sorry I have never came across grep. You mean I should be looking to do something like:
$sth = $dbh->prepare(q{select username, password from reg where username = ?}); $sth->execute($testUsername);

Replies are listed 'Best First'.
Re^5: accessing values in hash
by swampyankee (Parson) on Sep 04, 2006 at 03:16 UTC

    grep applies a test to all the elements of a list and creates a subset of the elements that pass the test. Using it in scalar context return the number of elements which passed the test.

    However, if you know the username first, I would suggest making the database do the work and re-writing the query to something like this (note that my SQL skills are quite rusty):

    $sth = $dbh -> prepare(q{select username, password from reg where user +name = $testUsername});

    Why return a list to Perl and check the entire list for the existence of username when the database can do exactly that? If you're testing a large number of user names, it may make more sense to query the database for a list, and then check the list for the for existence of all the user names(subject to the caution that the database may have been updated during the processing of the list).

    emc

    Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

    Albert Einstein
      But of course using placeholders :)

      ----------
      "Write a wise saying and your name will live forever." - Anonymous

        Now that I know about them, of course.

        emc

        Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.

        Albert Einstein