Monday, December 30, 2013

Capgemini - Perl Interview questions with additional answers

Below are the collection of technical questions asked in the telephonic round and F2F round in Capgemini interview for Production Support.
  • Brief about data structures in perl. 
Scalars, Arrays and Hashes
  • What are the differences between arrays and lists?
* Lists are constant data while arrays are variables.  
* Arrays have a name to identify them, while lists don't. 
* Elements of an array can be modified and stored in the same array variable but the same is not possible with lists. 
* Stack (push,pop) and queue (unshift,shift) operations are possible only on arrays and not possible on lists.
What are the differences between arrays and hashes?
* Arrays have numerals as indices while hashes have keys (strings) as indices.
* Arrays are often ordered list while hashes are unordered list.
  • Have you used modules in perl? Can you brief about a module and its functions or sub routines?
       1. File::Find
       2. File::Copy
       3. XML::Simple
       4. DBI
       5. WWW::Machanize
       6. CAM::PDF 
       7. CGI
       8. DBIx::Class
       9. Net::FTP 
  • Difference between use and require.
  • How to create objects in OO perl?
  • Write a perl script to validate an IP address.
A partly correct way is given here -- http://perl-interview-questions-answers.blogspot.in/2013/06/lets-see-who-finds-bug-in-this.html
  • How to sort a numeric array?
http://stackoverflow.com/questions/3574336/how-to-sort-numbers-in-perl
  • What are the differences between grep and map functions?
http://stackoverflow.com/questions/575490/whats-the-difference-between-grep-and-map-in-perl
  • How to sort a hash with key,values pairs as name_of_person,age based on their age?

%hash = #hash map of format name => age
(
"ganesh" => "26",
"kumaresh" => "27",
"kannan" => "30",
);
foreach $value (sort {$a <=> $b} values(%hash))
{
print "$value\n"
}
  • How to remove duplicate entries in an array?

my @arr = (1,2,2,3,4,4,5,5,5,6,6,1,1,1); #array having duplicates
my %hash;
foreach (@arr)
{
$hash{$_} = undef; #creating a hash key for each array element. this line  helps in removing duplicates since hash keys cannot be duplicated and new  duplicate key overwrites the old key.
}
my @res = keys %hash;
print "@res"; #prints array without puplicates
  • What is the use of @ISA array?

         @ISA is stand for ‘is a’, that means the array contains parents' package

  • Why do we need references?
    If we need to pass multiple arrays/hashes values into subroutine. In that case we used references.

No comments: