GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  Perl

 Print  |  
Question:  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. Submitted by  ilangocal.

Answer:
Here is the link for the full questions in exforsys forum, see if you can answer ttp://www.exforsys.com/forum/showthread.php?t=499


December 12, 2005 12:30:31 #1
 Vadivel raja   Member Since: Visitor    Total Comments: N/A 

RE: Here is a Perl Problem that was posed to me. I was...
 

i think the problem is straight forward and should be very simple to write a perl program for the same, below is the program. i havent run it to check if it works fine. comments are welcome

1. Assuming table 1 having the address has a structure

address_tbl (mailaddress char(255))

2. Assuming table 2 having the count of domains has a structure

domain_count_tbl (domain char(255), count int)


=========================================================================================

@maillist = query("select * from address_tbl")

for(i=0;i<scalar(@maillist;i++)
{
 (name,domain) = split(/@/, myvar[i])
 mylist[domain]++
}

foreach $key (keys %mylist)
{
 @res = query("select 1 from domain_count_tbl where domain=$key")
 if (scalar(@res) == 0 )
 {
  query(insert into domain_count_tbl values("$key",mylist[$key]))
 }
 else
 {
  query(update domain_count_tbl set count=mylist[$key] where domain="$key")
 }
}

     

 

Back To Question