Perl Interview Questions & Answers part 4

0
497

Q: – How to process a string one character at a time?

Use split with a null pattern to break up the string into individual characters
@array = split(//, $string);

Q: – How many for (while, if) blocks can I nest inside each other?

As many as you like

Q: – How can I eliminate duplicate elements from an array?

Use a hash. Hashes allow you to do some rather interesting manipulations on arrays quickly and efficiently.

Q: – Does Perl have a function for rounding?

The printf function usually does what you want for rounding when displaying numbers. If you really need the round function, check out the POSIX module, which has this function and many more.

Q: – Variables are interpolated inside qq quotes. True or False?

True

Q: – How to reverse the characters or words of a string.

Use the reverse function in scalar context for flipping bytes.
$revbytes = reverse($string);

Q: – How to add an entry to a hash?

Simply assign to the hash key:
$HASH{$KEY} = $VALUE;

Q: – Concatenation can be performed only with the concatenation operator (.). True or False?

False

Q: – How to convert a string Lower case to Upper case or Upper case to Lower case?

Use the lc and uc functions

Submitted By:-Sameer Dahiya            Email-ID: – samdahiya541@gmail.com

SHARE

LEAVE A REPLY