Interview Helper
Translate Page To German Tranlate Page To Spanish Translate Page To French Translate Page To Italian Translate Page To Japanese Translate Page To Korean Translate Page To Portuguese Translate Page To Chinese
[Valid RSS feed]
 
Number Times Read : 852    
 
  Go To Article :    
Categories

Air India (2)
Campus Interviews (505)
Career Helper (6)
Certification Dumps (10)
Code Samples (118)
Competitive Exams (163)
Interview Questions (4686)
Test Dev (0)
Test Director (25)
test... (0)
test_php (0)
Walkin Interviews (20)
 
Stats
Total Articles: 851
Total Authors: 781
Total Downloads: 1183168


Newest Member
sukhvir chahal
 
   

Question Popularity: 99 or more times read
Submitted 2008-11-05 10:16:47 [Valid RSS feed]


Perl Interview Questions 2






What are the two different types of data Perl handles?

Perl handles two types of data they are

(i) Scalar Variables and

(ii) Lists

Scalar variables hold a single data item whereas lists hold multiple data items.

What are scalar variables?

Scalar variables are what many programming languages refer to as simple variables. They hold a single data item, a number, a string, or a perl reference. Scalars are called scalars to differentiate them from constructs that can hold more than one item, like arrays.

How to open and read data files with Perl ?

Data files are opened in Perl using the open() function. When you open a data file, all you have to do is specify (a) a file handle and (b) the name of the file you want to read from.

As an example, suppose you need to read some data from a file named "checkbook.txt". Here's a simple open statement that opens the checkbook file for read access: open (CHECKBOOK, "checkbook.txt"); In this example, the name "CHECKBOOK" is the file handle that you'll use later when reading from the checkbook.txt data file. Any time you want to read data from the checkbook file, just use the file handle named "CHECKBOOK".

Now that we've opened the checkbook file, we'd like to be able to read what's in it. Here's how to read one line of data from the checkbook file:

$record = < CHECKBOOK > ;

After this statement is executed, the variable $record contains the contents of the first line of the checkbook file. The "<>" symbol is called the line reading operator.

To print every record of information from the checkbook file open (CHECKBOOK, "checkbook.txt") || die "couldn't open the file!";

while ($record = < CHECKBOOK >) {

print $record;

}

close(CHECKBOOK);

How many ways can we express string in Perl?

Many. For example 'this is a string' can be expressed in:

"this is a string"

qq/this is a string like double-quoted string/

qq^this is a string like double-quoted string^

q/this is a string/

q&this is a string&

q(this is a string)

What does Perl do if you try to exploit the execve(2) race involving setuid scripts?

Sends mail to root and exits.

It has been said that all programs advance to the point of being able to automatically read mail. While not quite at that point (well, without having a module loaded), Perl does at least automatically send it.

How do I do fill_in_the_blank for each file in a directory?

Here's code that just prints a listing of every file in the current directory:

#!/usr/bin/perl -w

opendir(DIR, ".");

@files = readdir(DIR);

closedir(DIR);

foreach $file (@files) {

print "$filen";

}

How do you print out the next line from a filehandle with all its bytes reversed?

print scalar reverse scalar

Surprisingly enough, you have to put both the reverse and the into scalar context separately for this to work.

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:

#!/usr/bin/perl -w

opendir(DIR, ".");

@files = grep(/.html$/,readdir(DIR));

closedir(DIR);

foreach $file (@files) {

print "$filen";

}

How does a “grep” function perform?

Grep returns the number of lines the expression is true. Grep returns a sublist of a list for which a specific criterion is true. This function often involves pattern matching. It modifies the elements in the original list.

Explain about Typeglobs?

Type globs are another integral type in perl. A typeglob`s prefix derefrencer is *, which is also the wild card character because you can use typeglobs to create an alias for all types associated with a particular name. All kinds of manipulations are possible with typeglobs.

Related Stuff
Answers
No answer submitted yet!! Be the first one to answer this question.
New Members
select
Sign up
select
learn more
Affiliate Sign in
Affiliate Sign In
 
Nav Menu
Home
Login
Submit Articles
Submission Guidelines
Top Articles
Link Directory
About Us
Contact Us
Privacy Policy
RSS Feeds

Actions
Print This Article
Add To Favorites

 
Sponsors

 

All Rights Reserved Interview Helper

Proudly associated with Job Interview Helper | Interviewhelper Articles