Search Question Papers

PEARL Technical Interview Questions

PEARL Technical Interview Questions

1. How do you know the reference of a variable whether it is a reference,scaller, hash or array?

Ans: there is a 'ref' function that lets you know -----------------------------------------------------------------


2. what is the difference between 'use' and 'require' function?

Ans: 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 extentsion. Require: 1. The method is used for both libraries ( package ) and modules 2. The include objects are varified at the run time. 3. Need to give file Extension. ----------------------------------------------------------------


3. What is the use of 'chomp' ? what is the difference between 'chomp' and 'chop'?

Ans. 'chop' functiononly 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' ------------------------------------------------------------------


4. Print this array @arr in reversed case-insensitive order

Ans> @solution = sort {lc $a comp lc$b } @arr. ------------------------------------------------------------------


5. What is '->' in Perl?

Ans. 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. --------------------------------------------------------------------


6. how do you check the return code of system call?

Ans. System calls "traditionally" returns 9 when successful and 1 when it fails. system (cmd) or die "Error in command"; --------------------------------------------------------------------


7. #create directory if not there
if (! -s "$temp/engl_2/wf"){ System "mkdir -p $temp/engl_2/wf"; } if (! -s "$temp/backup_basedir"){ system "mkdir -p $temp/backup_basedir"; } ${pack_2} = -M "${temp}/engl_2/wf/${wf_package_name}.data"; ${new_pack}= -M "{pack}/package.data"; What is the use of -M and -s in the above script?

Ans. -s means is filename a non-empty file -M how long since filename modified? -----------------------------------------------------------------------


8. How to substitute a particular string in a file containing million of record?

Ans. perl -p -ibak -e 's/search_str/replace_str/g' filename -----------------------------------------------------------------------


9. I have a variable named $objref which is defined in main package. I want to make it as a Object of class XYZ. how could I do it?

Ans. use XYZ my $objref =XYZ -> new() OR, bless $objref, 'XYZ'; ---------------------------------------------------------------


10. what is meant by a 'pack' in perl?

Ans. 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 contaings a con-catenation of the converted values. Typically, each converted values looks like its machine-level repesentation. for example, on 32-bit machines a converted integer may be representated by a sequence of 4 bytes. ---------------------------------------------------------------------------------------------------


11. how to implement stack in Perl?

Ans. through push() and shift() function. push adds the element at the last of array and shift() removes from the beginning of an array. ---------------------------------------------------------------------------------------------------


12. What is Grep used for in Perl?

Ans. Grep is used with regular expression to check if a parituclar value exist in an array. it returns 0 it the value does not exists, 1 otherwise. --------------------------------------------------------------------------------------------------


13. How to code in Perl to implement the tail function in unix?

And. You have to maintain a structure to store the line number and the size of the file at that time eg. 1-10bytes, 2-18bytes.. you have a counter to increase the number of lines to find out the number of lines in the file. once you are through the file, you will know the size of the file at any nth line, use 'sysseek' to move the file pointer back to that position (last 10) and thens tart reading till the end. ---------------------------------------------------------------------------------------------------


14. Explain the difference between 'my' and 'local' variable scope declarations?

Ans. Both of them are used to declare local variables. The variables declared with 'my' can live only within the block and cannot gets its visibility inherited fucntions called within that block, but one defined as 'local' canlive within the block and have its visibility in the functions called within that block. ------------------------------------------------------------------------------------------------------


15. How do you navigate thorugh an XML documents?

Ans. You can use the XML::DOM navigation methods to navigate thorugh an XML::DOM node tree and use the getnodevalue to recover the data. DOM Parser is used when it is neede to do node operation. Instead we may use SAX parser if you require simple processing of the xml structure.

Leave a Reply

Powered by Blogger.