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

Sorry, I posted before you posted your answer.

emc

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

Albert Einstein

Replies are listed 'Best First'.
Re^4: accessing values in hash
by mattdope (Acolyte) on Sep 04, 2006 at 00:16 UTC
    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);

      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