Exforsys

Online Training

Perl Interview question

This is a discussion on Perl Interview question within the Interview Questions forums, part of the Interviews and Job Listings category; Hi friends here is a Perl Problem that was posed to me. I was given one day time to solve. ...


Go Back   Exforsys > Career Management > Interviews and Job Listings > Interview Questions

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-16-2005, 04:40 PM
Junior Member
 
Join Date: Mar 2005
Posts: 1
ilangocal is on a distinguished road
Perl Interview question

Hi friends
here is a Perl Problem that was posed to me. I was given one day time to solve. Unfortunately I did not know enough Perl to do it. And sadly, I did not get selected.
However I wish to share this question with all. Please pose your answers or programs on this forum for the benefit of all friends.

---------
Given a table 'mailing':

CREATE TABLE mailing (
addr VARCHAR(255) NOT NULL
);

The mailing table will initially be empty. New addresses will be added
on a daily basis. It is expected that the table will store at least
10,000,000 email addresses and 100,000 domains.

Write a perl script that updates another table which holds a daily
count of email addresses by their domain name.

Use this table to report the top 50 domains by count sorted by
percentage growth of the last 30 days compared to the total.

** NOTE **
- You MUST use the provided DB.pm for all database interaction, and you
must use it as it is (DB.pm cannot be modified except for the
connection settings).

- The original mailing table should not be modified.

- All processing must be done in Perl (eg. no complex queries or
sub-queries)

- Submit a compressed file(tar/zip) with the files required to run your
script.
--------------- DB.pm file contents are as follows

package GUI:B;

use strict;
use DBI;

use vars qw(@ISA @EXPORT);
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(dbConnect query);

#
# dbConnect - connect to the database, get the database handle
#
sub dbConnect {

# Read database settings from config file:
my $dsn = "DBI:mysql:database=test";
my $dbh = DBI->connect( $dsn,
'',
'',
{ RaiseError => 1 }
);

return $dbh;

}

#
# query - execute a query with parameters
# query($dbh, $sql, @bindValues)
#
sub query {
my $dbh = shift;
my $sql = shift;
my @bindValues = @_; # 0 or serveral parameters

my @returnData = ();

# issue query
my $sth = $dbh->prepare($sql);

if ( @bindValues ) {
$sth->execute(@bindValues);
} else {
$sth->execute();
}

if ( $sql =~ m/^select/i ) {
while ( my $row = $sth->fetchrow_hashref ) {
push @returnData, $row;
}
}

# finish the sql statement
$sth->finish();

return @returnData;
}

__END__


Happy solving to all. Thanks. I am working on it too.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-04-2005, 09:41 PM
Junior Member
 
Join Date: Mar 2005
Posts: 1
DecisionSoft is on a distinguished road
That's a very good one, thanks.
__________________
DecisionSoft - XML experts in UK
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.