Perl Interview Questions For Experienced

Perl Interview Questions For Experienced

Java Online Training from India1. How do I generate a list of all .html files in a directory ?

Ans: Here’s a snippet of code that just prints a listing of every file in the current directory that ends with the extension .

html:
#!/usr/bin/perl -w
opendir(DIR, “.”);
@files = grep(/\.html$/,readdir(DIR));
closedir(DIR);
foreach $file (@files) {
print “$file\n”;
}.

2. What factors do you take into consideration to decide if Perl is a suitable programming language for a situation ?

Ans: If the project requires OOP programming but requires faster execution.

If the application to be developed is web based, Perl provides a lot of flexibility in programming such applications and is most popularly used.

Cost – As PERL is free, we can save on the cost of acquiring license for the programming language.

If the deadline is near, we can use CPAN, the Comprehensive Perl Archive Network, which is one of the largest repositories of free code in the world. If you need a particular type of functionality, chances are there are several options on the CPAN, and there are no fees or ongoing costs for using it.

3. When do you use Perl for programming ?

Ans: About PERL:
PERL is Practical Extraction and Reporting language, which is a high level programming language written by Larry Wall. The more recent expansion is Pathologically Eclectic Rubbish Lister .

PERL is a free open source language.
It is simple to learn as its syntax is similar to C.
It supports OOP – Object oriented programming like C++
Unlike C/ C++ it is a lot more flexible in usage.

When do we use PERL for Programming:
Generally PERL is used to develop web based applications even though libraries are available to program web server applications, database interfaces and networking components.
Example: The popular e-commerce site www.amazon.com was developed with PERL.

4. Explain the difference between ‘my’ and ‘local’ variable scope declarations ?

Ans: Both of them are used to declare local variables. The variables declared with ‘my’ can live only within the block and cannot gets its visibility inherited fucntions called within that block, but one defined as ‘local’ canlive within the block and have its visibility in the functions called within that block.

5. Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.

Ans:  Syntax:
$result = $firststring . ” “.$secondstring;

Program:  
#!/usr/bin/perl
$firststring = “abcd”;
$secondstring = “efgh”;
$combine = “$firststring $secondstring”;
print “$Combine\n”;

Output:
abcd efgh.

6. What is Perl one-liner ?

Ans: There are two ways a Perl script can be run:
–from a command line, called one-liner, that means you type and execute immediately on the command line. You’ll need the -e option to start like “C:\ %gt perl -e “print \”Hello\”;”. One-liner doesn’t mean one Perl statement. One-liner may contain many statements in one line.
–from a script file, called Perl program.

7. How would you ensure the re-use and maximum readability of your Perl code ?

Ans: 1.modularize code and include them where required using the “use” command.
2.use subroutines or functions to segregate operations thereby making the code more readable.
3.use objects to create programs wherever possible which greatly promotes code reuse.
4.include appropriate comments as and when required.
5.eliminate any dereferencing operator.

8. What factors do you take into consideration to decide if Perl is a suitable programming language for a situation ?

Ans: If the project requires OOP programming but requires faster execution.

If the application to be developed is web based, Perl provides a lot of flexibility in programming such applications and is most popularly used.

Cost – As PERL is free, we can save on the cost of acquiring license for the programming language.

If the deadline is near, we can use CPAN, the Comprehensive Perl Archive Network, which is one of the largest repositories of free code in the world. If you need a particular type of functionality, chances are there are several options on the CPAN, and there are no fees or ongoing costs for using it.

9.  How do you navigate thorugh an XML documents ?

Ans: You can use the XML::DOM navigation methods to navigate thorugh an XML::DOM node tree and use the getnodevalue to recover the data. DOM Parser is used when it is neede to do node operation. Instead we may use SAX parser if you require simple processing of the xml structure.

10. How many types of primary data structures in Perl and what do they mean ?

Ans: The scalar: It can hold one specific piece of information at a time (string, integer, or reference). It starts with dollar $ sign followed by the Perl identifier and Perl identifier can contain alphanumeric and underscores. It is not allowed to start with a digit. Arrays are simply a list of scalar variables.

Arrays: Arrays begin with @ sign. Example of array:

my @arrayvar = (“string a”, “string b “string c”);

Associative arrays: It also frequently called hashes, are the third major data type in Perl after scalars and arrays. Hashes are named as such because they work very similarly to a common data structure that programmers use in other languages–hash tables. However, hashes in Perl are actually a direct language supported data type.

Save