Series: Subject: Topic:

Perl Interview Questions

Showing Questions 1 - 20 of 65 Questions
First | Prev | | Next | Last Page
Sort by: 

I was asked how to implement the UNIX tail command in perl $ tail.Pl t.Txt 10 (display last 10 lines) I kind of managed with the simple array and they playing around with the $#array etc. But they wanted...

Asked By: vm | Asked On: Jun 14th, 2007

Answered by: vijth on: Oct 19th, 2014

  1. open(data, "<file.txt")
  2. $count=0;
  3. $value=<data>;
  4. $length=length(value);
  5. while (<data>)
  6. {
  7. if ($count >= length-10)
  8. {print "<data>";}
  9. }

Answered by: pp on: Oct 15th, 2014

1) open the file
2) assign it to an array(each line will be an element)
3) Get the length of the array(L)
4) Starting from L-10 .. L , assign elements to another array @new = @old[L-10..L];
5) print the new array , separate elements by newline

Print this array, sorted in reversed case-insensitive order...

Asked By: Namataraginu | Asked On: Jan 31st, 2008

You have unsorted array of strings, like:my @arr = qw(hello world show must go on);print this array, sorted in reversed case-insensitive order.

Answered by: Matt LaSaine on: May 29th, 2014

  1. my @arr = qw(hello world Show Must go on);
  2. print join(" ", sort {lc($b) cmp lc($a)} @arr), "
  3. ";

Answered by: j0eb0b on: Oct 31st, 2009

my @arr = qw(hello World Show must go on);#close print "@arr nreverse sorted: ", join(", ", reverse sort map {lc $_} @arr), "n"; #closer print "@arr nreverse sorted:...

When do you not use perl for a project?

Asked By: suseel | Asked On: May 16th, 2006

Answered by: CHAKRAPANI PATEL on: May 29th, 2014

Also if you are processing files (size in GB).

Answered by: Rajan Chayanam on: Nov 19th, 2013

We would not opt PERL for the following : 1. Basic text manipulation (can be done with shell scripting) 2. For a web application having huge traffic like (twitter/facebook) etc. 3. To develop a CMS...

What is the difference between die and exit in perl?

Asked By: Godhuly | Asked On: Jan 12th, 2007

Answered by: george on: Oct 11th, 2013

Die will print a message to the std err, then exit with a non-zero return code. You dont control the return code and you are stuck with the text going to the std err. Exit will terminate with a speci...

Answered by: vinod on: Jun 20th, 2013

Exit will simply end the program but die will print the message before ending the program

How to remove a directory which has few files in it? I know about rmdir however it does not remove a dir which has files/dir in it!

Asked By: Chintz | Asked On: Nov 23rd, 2006

Answered by: Navrattan on: Oct 8th, 2013

Rmtree () is function which is used to remove a directory which has files in it

Answered by: maulikthaker on: Dec 16th, 2009

$dir = /path/system("rm -Rf $dir");

Perl code

Asked By: ashwinraot | Asked On: Aug 29th, 2012

1) input ip address. Check if it is in the range and using only regular expressions in perl. Do not use parse functions. 2) input a name. Check if it is valid (has at-least 3 letters and one vowel) using only return functions and regular expressions in perl. Do not use parse...

Answered by: Sachin on: Sep 17th, 2013

This worked perfectly for me to find the range between and!/usr/bin/perl$_ =;if($_=~ /172.125.(2[0-5]|1[0-9]|[1-9]).(2[0-5]|1[0-9]|[0-9])/){print $&;print "Match"; }else{print "not match";}

Answered by: Rudra on: Sep 9th, 2013

In generic we can validate the IP address as

What's the significance of @isa, @export @export_ok %export_tags list & hashes in a perl package? With example?

Asked By: geek_zubi | Asked On: Feb 22nd, 2006

Answered by: Jatin on: Jan 5th, 2013

%EXPORT_TAGS = (tag_name => [anonymous array/Array reference]); It is to provide the tag to Anonymous array/Array reference which is generally @EXPORT_OK for example: %EXPORT_TAGS = (all => @EXPORT_O...

Answered by: terrytlin on: Dec 3rd, 2009

Package NewModule;use Exporter; # an application by ‘use’ operator.# This Exporter package has @ISA array to look for a specific method, this array keeps track of classes it is inheriting....

Difference between for & foreach,exec & system?

Asked By: suseel | Asked On: May 16th, 2006

Answered by: VINOD on: Jul 22nd, 2012

For is iterating thorough indices and foreache is iterating through element value.

Exec will execute the command and will not return to the same program from which it was called. System will also execute the command and it will return back to same program from which it was called.

Answered by: Joe Doe on: Jul 8th, 2006

- Technically, there's no difference between for and foreach other than some style issues. One is an alias of another. You can do things like this foreach (my $i = 0; $i < 3; ++$i) { # norma...

What is meant by 'chomp'? Where do we require this ?

Asked By: suseel | Asked On: May 19th, 2006

Answered by: babu on: Jun 20th, 2012

Hi i am babu.chomp is pre define function it will delete last character if it is a new line character ex1:$a="babu "; chomp($a); print $a;#it will not print new line ...after babu. ex2:print "Enter a...

Answered by: sergant on: Apr 27th, 2012

chomp VARIABLE chomp( LIST ) chomp This safer version of "chop" removes any trailing string that corresponds to the current value of $/ (also known as $INPUT_RECORD_SEPARATOR in...

Soap client

Asked By: OPENVMS | Asked On: Dec 27th, 2011

Hi I want to write a simple soap client in perl. if we pass the interger value as a http request. 1. Take an integer or string as command line arguments. 2. Create a http request. 3. Get the response from http. 4. Store the response in xsd schema. please help me out how to write perl soap client.

What is grep used for in perl?

Asked By: ms_2007 | Asked On: Nov 10th, 2007

Answered by: vasu on: Dec 19th, 2011

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. my @myNames = (Jacob, Michael, Joshua, Matthew, Alexander, Andrew);
  5. my  @grepNames = grep(/^m(.*)$/i, @myNames);
  6. foreach my $grepNames (@grepNames) {
  7.         print"the value is :".$grepNames."
  8. ";
  9. }

Answered by: contactparagm on: Dec 3rd, 2010

"grep" is a built function which extract all elements in ARRAY, matched by regex/pattern given as argument for grep and return the resultant elements in an array.perl syntax:  &nbs...

Install perl module using cpan

Asked By: Tanu_shree | Asked On: Sep 13th, 2008

How to install perl module using cpan. How to include the module in a program?

Answered by: ankitloud on: Nov 20th, 2011

I think the best option will be : type following command on command prompt

cpan App::cpanminus then you can install any module using its name using following command

cpan Module::Apache

let me know if it doesn't work

Answered by: Navshere on: Aug 19th, 2011

Perl Makefile.PL
nmake test
nmake install

# To check successive installation
perl -e "use Twig"

Create a perl script to store the information in excel

Asked By: Cristine Thine | Asked On: Apr 13th, 2011

Hello,--------------------------------------id name address1 cristine new york 2 murray redmond3 kumar Sunnyvale --------------------------------------this is 'samples.Xlsx' file.'id' string in a1, 'name' in b1, 'address' in c1 column in excel file.Create...

Answered by: elavv on: Aug 10th, 2011

You can construct one hash where the the emp id as key to the hash and rest of the elements as values in the structure of array ref. "perl #! use strict; use Spreadsheet::ParseExce...

Create a perl script

Asked By: Cristine Thine | Asked On: Apr 13th, 2011

Hello,------------------------------------------- id name address 1 cristine new york 2 murray redmond 3 kumar Sunnyvale-------------------------------------------this is 'sample.Xlsx' file. (can't attach the image.)'id' string in a1,...

Answered by: Elavazhagan on: Aug 10th, 2011

Keep the student id as key to a hash and the rest of the elements are the array reference.

How do you you check the return code of a command in perl

Asked By: mpathak | Asked On: Dec 5th, 2007

Suppose you run a program/script in perl:system("./server ....");how will you check the return code?

Answered by: contactparagm on: Dec 3rd, 2010

Perl defines predefined variable $? which gives the return code of last command executed.

Answered by: amitkshirsagar on: Jun 22nd, 2009

$r = system("command .. e.g. search");print"r is $rn";Here, if $r is 0, that means command has executed successfully.Any other value means command has failed.

What is the difference between the function oriented and object oriented approach in the modules (cpan). Mention the merits as well demerits of these two types.

Asked By: rajashekar | Asked On: Oct 25th, 2007

Answered by: shalusanju on: Aug 13th, 2010

In the object-oriented style you create one or more CGI objects and then use object methods to create the various elements of the page. Each CGI object starts out with the list of named parameters tha...

What is -> symbol in perl

Asked By: Rajivcitcse2000 | Asked On: Nov 27th, 2007

Answered by: shalusanju on: Aug 13th, 2010

In object oriented PERL, the arrow -> symbol is used for creating or accessing a particular object of a class. For eg. in Perl/Tk 1. use Tk; my $main_win = MainWindow->new(); Here we u...

Answered by: ajit_saley on: Jul 15th, 2009

$arr= [1, 2,2+1 ,3+1];print "n arr[1]=|".$arr->[1]."|".$$arr[1]."|";

How to implement stack in perl?

Asked By: ms_2007 | Asked On: Nov 10th, 2007

Answered by: singh_Pushpendra on: Aug 13th, 2010

#! /usr/bin/perl -w$str1="Pushpendra Singh";@str=split("", $str1);@stack_array=();foreach $i (@str){ print "nt Item being pushed is : $i"; push(@stack_a...

Answered by: wow_suraj on: May 2nd, 2008

In perl stacks are easy to be implemented. Stacks which follows LIFO (Last In First Out) data structure can be handled in perl with 'POP' and 'PUSH' keywords. POP Example:my $strT...

How to substitute a particular string in a file containing millions of records?

Asked By: ms_2007 | Asked On: Nov 10th, 2007

Answered by: ratul2783 on: May 3rd, 2010

perl -p -i -e "s/search_string/replace_string/g" SourceFileThe -p option ensures that $_ is assigned each line of each input file in turn and that the program is executed once for each input line.The ...

Answered by: vinod_rapolu on: Nov 14th, 2008

Perl -pi -e "s/search_string/replace_string/g" SourceFile

Rename datastage jobs through perl

Asked By: s4sweety | Asked On: Jul 18th, 2008

Please provide me perl scriptwhich reads the data from xcel sheet and renames the dsx file.Process followed to rename is:make a list of old and new file names in xcel sheet.Compare the old file name in the xcel sheet with dsx name.If both are equal then assign the new name to the dsx which is mentioned...

Answered by: gansi on: Sep 30th, 2009

use Win32::OLE;use Win32::OLE::Enum;use Win32::OLE qw(in with);use Win32::OLE::Const 'Microsoft Excel';use Win32::OLE::Variant;use Spreadsheet::ParseExcel;use Spreadsheet::WriteExcel;use Sprea...

First | Prev | | Next | Last Page





twitter fb Linkedin GPlus RSS


Interview Question

 Ask Interview Question?


Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.