Perl Programming Interview Questions and Answers

Perl Programming Questions and Answers:

1 :: How do you give functions private variables that retain their values between calls?

Create a scope surrounding that sub that contains lexicals.
Only lexical variables are truly private, and they will persist even when their block exits if something still cares about them. Thus:
{ my $i = 0; sub next_i { $i++ } sub last_i { --$i } }
creates two functions that share a private variable. The $i variable will not be deallocated when its block goes away because next_i and last_i need to be able to access it.
0/5 Rating (0 vote)
Is This Answer Correct?    0 Yes 0 No
Place Your Answer

2 :: 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)
0/5 Rating (0 vote)
Is This Answer Correct?    0 Yes 0 No
Place Your Answer

3 :: How do I print the entire contents of an array with Perl?

To answer this question, we first need a sample array. Let's assume that you have an array that contains the name of baseball teams, like this:
@teams = ('cubs', 'reds', 'yankees', 'dodgers');
If you just want to print the array with the array members separated by blank spaces, you can just print the array like this:
@teams = ('cubs', 'reds', 'yankees', 'dodgers');
print "@teamsn";
But that's not usually the case. More often, you want each element printed on a separate line. To achieve this, you can use this code:
@teams = ('cubs', 'reds', 'yankees', 'dodgers');
foreach (@teams) {
print "$_n";
}
0/5 Rating (0 vote)
Is This Answer Correct?    0 Yes 0 No
Place Your Answer

4 :: How do you match one letter in the current locale?

/[^W_d]/
We don't have full POSIX regexps, so you can't get at the isalpha() <ctype.h> macro save indirectly. You ask for one byte which is neither a non-alphanumunder, nor an under, nor a numeric. That leaves just the alphas, which is what you want.
0/5 Rating (0 vote)
Is This Answer Correct?    0 Yes 0 No
Place Your Answer

5 :: Assume that $ref refers to a scalar, an array, a hash or to some nested data structure. Explain the following statements:

$$ref; # returns a scalar
$$ref[0]; # returns the first element of that array
$ref- > [0]; # returns the first element of that array
@$ref; # returns the contents of that array, or number of elements, in scalar context
$&$ref; # returns the last index in that array
$ref- > [0][5]; # returns the sixth element in the first row
@{$ref- > {key}} # returns the contents of the array that is the value of the key "key"
0/5 Rating (0 vote)
Is This Answer Correct?    0 Yes 0 No
Place Your Answer

Rate This Category:
5/5 Rating (1 vote)
Place Your Question



Top: Perl Programming Interview Questions and Answers
Perl Programming Interview Questions and Answers

Top Frequently Asked Perl Programming Question
Frequently Asked Perl Programming Job Interview Question


Top Frequently opened Computer Programming Job Interview categories
Most popular Computer Programming Job Interview categories

Comments About Perl Programming Interview Questions and Answers

Share your valuable opinions, ideas and suggestions about Perl Programming Interview Questions and Answers
While placing your comment your email address is required but won't be published any where else; Personal information will be kept confidential; we do not sell or release our respective visitors private information.
  1. Webmaster 23rd of May 2012

    Webmaster Said

    Tell us what you feel about Perl Programming Interview Questions and Answers
    All comments will be published after review. No login or registration is required to post a comment on Perl Programming Interview Questions and Answers We offer and invite you to submit your valuable comment now; Please be respectful of others when commenting. Insulting others, self-promotional comments, website promotional comments, marketing stuff, SEO Techniques, SMS-style content and off-topic comments will not be approved at this information portal.
    So start sharing your thoughts regarding Perl Programming Interview Questions and Answers
    Thank you.

Leave a Comment

Leave a Comment
  1.  Enter This Verification Code  Regenerate Verification Code  



Your reply will be added to the comment above (Below any other replies to this comment) -

Top Comments About: Perl Programming Interview Questions and Answers
Comments on Perl Programming Interview Questions and Answers

 
Top of Link batk to Perl Programming Interview Questions and Answers
Link batk to Perl Programming Interview Questions and Answers