Capgemini Perl Technical Interview Questions and Answers
Perl (Practical Extraction and Report Language) remains a powerful scripting language, widely used in automation, text processing, system administration, and backend scripting. If you’re preparing for a Capgemini technical interview that involves Perl, you can expect both theoretical questions and hands-on coding challenges.
Below, I’ve compiled a set of frequently asked Perl interview questions with answers, covering basic, intermediate, and advanced levels.
1. Basic Perl Interview Questions
Q1. What is Perl?
Perl is a high-level, general-purpose scripting language known for its text-processing capabilities. It’s widely used in system administration, CGI scripting, network programming, and database interaction.
Q2. What are the main features of Perl?
Strong text and regular expression handling
Portable and cross-platform
Rich CPAN (Comprehensive Perl Archive Network) library
Supports both procedural and object-oriented programming
Rapid development for automation scripts
Q3. What is the difference between my
, local
, and our
in Perl?
my – Declares a lexical (scoped) variable, available only within its block.
local – Temporarily backs up and replaces a global variable within a block.
our – Declares a package global variable accessible across the package.
Q4. How do you comment in Perl?
Single-line comment:
# This is a comment
Multi-line: Use POD (Plain Old Documentation) format with
=begin
and=cut
.
Q5. What are scalar, array, and hash variables in Perl?
Scalar (
$
) – Stores a single value. Example:$x = 10;
Array (
@
) – Stores an ordered list. Example:@arr = (1, 2, 3);
Hash (
%
) – Stores key-value pairs. Example:%hash = ('name' => 'John', 'age' => 30);
2. Intermediate Perl Interview Questions
Q6. What are Perl’s data types?
Scalars – Numbers, strings
Arrays – Ordered list of scalars
Hashes – Key-value mappings
References – Pointers to arrays, hashes, or functions
Q7. How are regular expressions used in Perl?
Perl is famous for its regex support. Example:
if ($text =~ /Perl/) {
print "Found Perl!";
}
Here, =~
checks if $text
contains the word "Perl".
Q8. How do you read input from the user in Perl?
print "Enter your name: ";
my $name = <STDIN>;
chomp($name); # Removes newline
print "Hello $name\n";
Q9. What is the difference between use
, require
, and do
in Perl?
use – Loads modules at compile time.
require – Loads files at runtime, used mainly for libraries.
do – Executes a file as a Perl script.
Q10. How do you connect Perl to a database?
Using DBI module:
use DBI;
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost","user","password");
3. Advanced Perl Interview Questions
Q11. What is context in Perl?
Perl evaluates expressions based on context:
Scalar context – Returns a single value.
List context – Returns a list of values.
Example:
my @arr = (1,2,3);
print scalar @arr; # prints 3
Q12. What are Perl references?
References act as pointers to variables, arrays, or hashes. Example:
my @arr = (1, 2, 3);
my $ref = \@arr;
print $ref->[0]; # prints 1
Q13. What is CPAN in Perl?
CPAN (Comprehensive Perl Archive Network) is a large collection of Perl modules contributed by the community. It allows developers to easily install and use prebuilt libraries.
Q14. How do you handle exceptions in Perl?
Using eval
block:
eval {
die "Something went wrong!";
};
if ($@) {
print "Error: $@";
}
Q15. Explain object-oriented programming (OOP) in Perl.
Perl does not have built-in OOP syntax like Java or C#, but uses packages and bless function.
Example:
package Student;
sub new {
my $class = shift;
my $self = { name => shift };
bless $self, $class;
return $self;
}
sub getName {
my $self = shift;
return $self->{name};
}
1;
4. Real-Time Perl Scenario-Based Questions
Q16. How do you process a large log file efficiently in Perl?
Use filehandles with
while(<FH>)
instead of reading whole file at once.Apply regex filters for line-by-line matching.
Q17. How do you pass command-line arguments to a Perl script?
Arguments are stored in the @ARGV
array. Example:
print "First argument: $ARGV[0]\n";
Q18. How do you find duplicate entries in an array using Perl?
my @arr = (1,2,2,3,4,4);
my %seen;
foreach my $i (@arr) { $seen{$i}++ }
foreach my $k (keys %seen) {
print "$k is duplicate\n" if $seen{$k} > 1;
}
Q19. How do you handle file operations in Perl?
open(my $fh, "<", "file.txt") or die "Can't open file: $!";
while (my $line = <$fh>) {
print $line;
}
close $fh;
Q20. What’s the difference between Perl and Python?
Perl is stronger in regex and text processing, Python is better for general-purpose scripting.
Perl uses sigils (
$
,@
,%
) for variables, Python does not.Python is more readable, Perl is more flexible but sometimes cryptic.
Final Thoughts
At Capgemini Perl interviews, you can expect:
Questions on regex, arrays, hashes, and file handling
Hands-on coding for automation tasks
Real-world problem-solving involving text parsing and database connectivity
If you master Perl fundamentals, advanced concepts, and best practices, you’ll have a strong edge in clearing the interview.
Tags: Capgemini Perl Technical Interview Questions And Answers