Perl FAQ’s – 2 (Interview questions, frequently asked questions)
|
How do I generate a list of all .html files in a directory? Here’s a snippet of code that just prints a listing of every file in the current directory that ends with the extension .html: What is Perl one-liner? There are two ways a Perl script can be run: Assuming both a local($var) and a my($var) exist, what’s the difference between ${var} and ${”var”}? ${var} is the lexical variable $var, and ${”var”} is the dynamic variable $var. What happens when you return a reference to a private variable? Perl keeps track of your variables, whether dynamic or otherwise, and doesn’t free things before you’re done using them. How to turn on Perl warnings? Why is that important?
What are scalar data and scalar variables? Perl has a flexible concept of data types. Scalar means a single thing, like a number or string. So the Java concept of int, float, double and string equals to Perl\’s scalar in concept and the numbers and strings are exchangeable. Scalar variable is a Perl variable that is used to store scalar data. It uses a dollar sign $ and followed by one or more aphanumeric characters or underscores. It is case sensitive. Why should I use the -w argument with my Perl programs? Many Perl developers use the -w option of the interpreter, especially during the development stages of an application. This warning option turns on many warning messages that can help you understand and debug your applications. Assuming $_ contains HTML, which of the following substitutions will remove all tags in it? You can’t do that. I want users send data by formmail but when they send nothing or call it from web site they will see error. In php it will be like What is the output of the following Perl program? prog1.cpp Why aren’t Perl’s patterns regular expressions? Because Perl patterns have backreferences. What does Perl do if you try to exploit the execve(2) race involving setuid scripts? Sends mail to root and exits. How do I do < fill-in-the-blank > for each element in a hash? Here's a simple technique to process each element in a hash:
#!/usr/bin/perl -w
%days = (
'Sun' =>'Sunday',
'Mon' => 'Monday',
'Tue' => 'Tuesday',
'Wed' => 'Wednesday',
'Thu' => 'Thursday',
'Fri' => 'Friday',
'Sat' => 'Saturday' );
foreach $key (sort keys %days) {
print "The long name for $key is $days{$key}.\n";
How do I sort a hash by the hash key? Suppose we have a class of five students.
Their names are kim, al, rocky, chrisy, and jane.
Here's a test program that prints the contents
of the grades hash, sorted by student name:
#!/usr/bin/perl -w
%grades = (
kim => 96,
al => 63,
rocky => 87,
chrisy => 96,
jane => 79,
);
print "\n\tGRADES SORTED BY STUDENT NAME:\n";
foreach $key (sort (keys(%grades))) {
print "\t\t$key \t\t$grades{$key}\n";
}
The output of this program looks like this:
GRADES SORTED BY STUDENT NAME:
al 63
chrisy 96
jane 79
kim 96
rocky 87
}
} How do you print out the next line from a filehandle with all its bytes reversed? print scalar reverse scalar <FH> Related Jobs: |
Publish date: October 29, 2008 1:46 am | Tags: download perl, frequently asked questions, interview questions, pelr, Perl, realtime

Leave a Comment