CGI Perl Interview Preparation Guide
Download PDF

CGI Perl frequently Asked Questions by expert members with experience in CGI Perl. So get preparation for the CGI Perl job interview

18 CGI Perl Questions and Answers:

1 :: Write an expression or Perl script to identify the entered IP address is valid or not?

#! /usr/bin/per
use strict;
#- Use Input
my $ip_add = "";

#- Script start
print"Enter the IP address\n";
$ip_add = <STDIN>;
chomp($ip_add); # Remove the last "\n" character
$ip_add=$ip_add."\."; # Append . at the end of IP address
#-------Expression to check IP address is valid or not-----#
if($ip_add =~ m/^[0-2]?[0-5]?[0-5]?\.){4}$){
print" Valid IP Address\n";
print" Invalid IP Address\n"

2 :: Packing and Unpacking.

Hi, I want to get output as 0x23400000345....
in the below example How to get?
i tried out, but unable to get the answer

$y=pack(L L,$t,$r);
printf("\nThe value is $x1");

I didnt get constant output?

use the following code.

use bigint;

my $r = 0x234;
my $t = 0x345;

my $x1 = $r << 32 | $t;

print $x1->as_hex;

3 :: How to sort dates in Perl?

use Data::Dumper;
my @dates = ( "02/11/2009" , "20/12/2001" , "21/11/2010" ) ;
@dates = sort { join( '', (split '/', $a)[2,1,0] ) cmp
join( '', (split '/', $b)[2,1,0]) } @dates;
print Dumper \@dates;

4 :: Sort a word "system" in perl/shell without using built in functions output should be emssty?


my $word = $ARGV[0];
$sortword = "";
$lastchar = "";

while($word =~ /(.)/g)
$lastchar = $1;
if( $sortword ) {
$flag = "";
$newsortword = "";
while($sortword =~ /(.)/g) {
if( $lastchar gt $1 || $flag
eq "charcovered") {

$newsortword =
$flag = "greater" if($flag
ne "charcovered")
else {
$newsortword =
$flag = "charcovered";
if( $flag ne "charcovered" ) {
$newsortword =

$sortword = $newsortword;
else {
$sortword = $lastchar;

print $sortword."\n";

5 :: How to find a substring in a string without using substr built in functions, and print the substring found?


@n=split (//,$r);
print "@n\n";

print "@t\n";
print "$r\n";

6 :: Write a script to reverse a string without using Perls built in function?

my $i;
my $str="hello";
my @str=split('',$str);


print $str[$i];

7 :: Try pattern matching for the following:
2) /root/abc/cde/fgg/ac.xml --> Get file name without extention.
3) /root/abc/ac.xml/fgg/ac.xml --> Get file name without extention.
4) What does "DIE" meant in PERL?
5) chomp
6) "This is saturday" --> Print the weekday number.
7) 11-2-2009 --> Print the name of the month.
8) Reverse the string without using func in C.?

my $str="This is testing of string reverse";
print scalar reverse $s

chomp is used to remove the trailing new line.
If we give chomp list then it will remove the trailing new
line in all the elements of the list.

die function is used for handling the errors in Perl.
It terminates the program immediately after printing the
message passed to the die function.
die("testing of die");
It will print the message "testing of die" on screen and
terminates the program.

Pattern Matching

my $str="";
my $file="/root/abc/cde/fgg/ac.xml";
my $file1="/root/abc/ac.xml/fgg/ac.xml";
print "Pattern $& get matched\n";
print "File Name is $file1\n";
print strftime("%B",0,0,0,11,2-1,2009);


8 :: Why do you use only Perl when there a lot of more languages available in market like C, Java?

compare to other c and java perl is having strong regular
expression concept so data extraction will be easier and
complition will be faster too

9 :: What is the meaning of rigging?

Rigging is use for if we want to give animation for any
object or character then we apply to character or object
internel bone setting(like our bones).that is called
rigging. when apply rigging, then we can give proper

10 :: What is the difference between having a parenthesis after module name and without parenthsis after module name?
i.e Package::Module();
and Package::Module;

Package::Module(); This will throw as error,

I think,the question should be as: What is the difference
Package::MyModule qw(); # FIRST
Package::MyModule; # SECOND

# FIRST :- This will not import any subroutine from MyModule.
# SECOND :- This will import all the subroutine from the