Listing 3: Retrieve-people.pl, a Program That Uses People.pm to Retrieve Information from the Database
#!/usr/bin/perl -w
use strict;
use People;
# Create a new People instance
my $people = new People;
# Set the current person by name
$people->set_current_person_by_name("Shai", "Re'em")
|| die "Error retrieving person.";
# Get information about this person
my $info = $people->get_current_info();
# Print the information
foreach my $key (sort keys %{$info})
{
if (defined $info->{$key})
{
print "key => $info->{$key}\n";
}
}
print "-" x 60, "\n";
# -----------------------------------------------
# Now insert a new person
my $success = $people->new_person(first_name => "Reuven",
last_name => "Lerner",
country => "Israel",
email => 'reuven@lerner.co.il',
phone => '08-973-2225');
if ($success)
{
# Get information about this person
$info = $people->get_current_info();
# Print the information
foreach my $key (sort keys %{$info})
{
if (defined $info->{$key})
{
print "$key => $info->{$key}\n";
}
}
}
else
{
print "Error!\n";
}
exit;
# -----------------------------------------------
# Now set the first name to something different
$people->update_first_name("Yochai");
# Get information about this person
$info = $people->get_current_info();
# Print the new information
foreach my $key (sort keys %{$info})
{
if (defined $info->{$key})
print "$key => $info->{$key}\n";
}
}
print "\n";