Perl interview answers
- How do you know the reference of a variable whether it is a reference, scaller, hash or array?
There is a 'ref' function that lets you know
- What is the difference between 'use' and 'require' function?
Use: 1. the method is used only for modules (only to include .pm type file) 2. the included object are verified at the time of compilation. 3. No Need to give file extension. Require: 1. The method is used for both libraries (package) and modules 2. The included objects are verified at the run time. 3. Need to give file Extension.
- What is the use of ‘chomp’? What is the difference between 'chomp' and 'chop'?
'chop' functionality removes the last character completely 'from the scaler, where as 'chomp' function only removes the last character if it is a newline. by default, chomp only removes what is currently defined as the $INPUT_RECORD_SEPARATOR. whenever you call 'chomp ', it checks the value of a special variable '$/'. whatever the value of '$/' is eliminated from the scaler. by default the value of '$/' is 'n'
- Print this array @arr in reversed case-insensitive order
@solution = sort {lc $a comp lc$b } @arr.
- What is '->' in Perl?
It is a symbolic link to link one file name to a new name. so lets say we do it like file1-> file2, if we read file1, we end up reading file2.
- How do you check the return code of system call?
System calls "traditionally" returns 9 when successful and 1 when it fails. system (cmd) or die "Error in command";
- How to substitute a particular string in a file containing million of record?
Perl -p -ibak -e 's/search_str/replace_str/g' filename
- I have a variable named $objref which is defined in main package. I want to make it as an object of class XYZ. How could I do it?
Use XYZ my $objref =XYZ -> new() OR, bless $objref, 'XYZ';
- What is meant by a 'pack' in perl?
Pack converts a list into a binary representation. Takes an array or list of values and packs it into a binary structure, returning the string containing the structure. It takes a LIST of values and converts it into a string. The string containing a con-catenation of the converted values. Typically, each converted values looks like its machine-level representation. For example, on 32-bit machines a converted integer may be represented by a sequence of 4 bytes.
- How to implement stack in Perl?
Through push() and shift() function. push adds the element at the last of array and shift() removes from the beginning of an array.
Click on the link to search and apply for Perl jobs
Answers sourced from www.techinterviews.com
Comment
Log in or create your account to react to the article.