print records that match regexp



I have a table "customer_table" with the following fields:

Id int,
firstname varchar(64),
lastname varchar(64),
emailaddress varchar(64) not null primary key
city varchar (32),

Can some one help me and show me how to print only records that
matches a given regexp using, for example if I run:

#> getRecord.pl A+

should return all record from the database if the first name, last
name, or email address starts with a capital A

OR:

#> getRecord.pl

should return all records from the table, which I have it this way and
it works just fine:

use DBI;

my $dataBaseDriver = "DBI:mysql";
my $dataBaseName = "test";
my $dataBaseUser = "user";
my $dbUserPass = "user1234";
my $tableName = "my_table";

#---------------------------------------#
# connect to the database #
#---------------------------------------#

my $dbh = DBI->connect("$dataBaseDriver:$dataBaseName",
$dataBaseUser,
$dbUserPass,
{ RaiseError => 1,
AutoCommit => 0 }) || die "ERROR-1: Couldn't
connect to $dataBaseHost: " . DBI->errstr();
print "Connection to the database successful.\n";

#---------------------------------------#
# querying the database #
#---------------------------------------#
my $sth = $dbh->prepare("SELECT * FROM $tableName");
$sth->execute();

#---------------------------------------#
# print the data #
#---------------------------------------#
while(my $ref = $sth->fetchrow_hashref()) {
print "ID: $ref->{'Id'}\n";
print "First Name: $ref->{'firstname'}\n";
print "Last Name: $ref->{'lastname'}\n";
print "Email Address: $ref->{'emailaddress'}\n";
print "City: $ref->{'city'}\n";
}
$sth->finish();
$dbh -> disconnect();


Thanks for your help

Berti

.



Relevant Pages

  • Re: problem using identity column as primary key
    ... >> I am thinking of creating an identity column to use it as primary key ... More and more programmers who have absolutely no database training are ... the gap in the sequence is not filled in and the sequence ... vin CHARNOT NULL REFERENCES Motorpool); ...
    (microsoft.public.sqlserver.programming)
  • Re: Updating the SQL key value
    ... before creating the database, by the time I've come to pick a primary key, ... articles, each of which must be issued under a particular licence (e.g. ... GPL GNU General Public Licence http://www.gnu ... ...
    (comp.lang.php)
  • Re: Concatenate and Null Values -- Features
    ... Tony Toews dislikes cascade deletes as well as cascade updates, ... fence regarding the use of natural versus surrogate (autonumber) keys. ... Database Normalization Tips ... For optimal database design and performance, the primary key of a table ...
    (microsoft.public.access.reports)
  • Re: Option groups, radio buttons and reports...oh my!!
    ... designing a 'questionnaire' database of using separate columns for the ... referencing the primary key of the Questions and Answers table. ... composite primary key of QuestionAnswers. ... a composite one of RespondentID and QuestionID; ...
    (microsoft.public.access.gettingstarted)
  • Re: AutoNumber Question
    ... I would like to point out that a primary key does not need to be meaningless ... database, as it would be if it was part of relationships. ... VIN is being reused. ... so a VIN has meaning separate from ...
    (microsoft.public.access.tablesdbdesign)