Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Download
Standard view
Full view
of .
Add note
Save to My Library
Sync to mobile
Look up keyword
Like this
247Activity
×
0 of .
Results for:
No results containing your search query
P. 1
Perl Interview Question

Perl Interview Question

Ratings:

5.0

(7)
|Views: 43,646|Likes:
Published by towid
Frequently asked perl interview questions and answers
Frequently asked perl interview questions and answers

More info:

Published by: towid on Feb 27, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, DOC, TXT or read online from Scribd
See More
See less

01/12/2013

pdf

text

original

 
Perl Interview Question.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. theincluded 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 includeobjects 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 onlyremoves 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 '$/' iseliminated 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 likefile1-> 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 thereif (! -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 asa 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 aLIST of values and converts it into a string. The string contaings a con-catenation of theconverted values. Typically, each converted values looks like its machine-levelrepesentation. 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 andshift() 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 atthat time eg. 1-10bytes, 2-18bytes.. you have a counter to increase the number of lines tofind out the number of lines in the file. once you are through the file, you will know thesize 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 calledwithin that block, but one defined as 'local' canlive within the block and have its visibilityin 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 anXML::DOM node tree and use the getnodevalue to recover the data. DOM Parser is usedwhen it is neede to do node operation. Instead we may use SAX parser if you requiresimple processing of the xml structure.-------------------------------------------------------------------------------------------------------16. How to delete an entire directory containing few files in the directory?Ans. rmtree($dir); OR, you can use CPAN module File::Remove Though it sounds likedeleting file but it can be used also for deleting directories. &File::Removes::remove(1,$feed-dir,$item_dir);-----------------------------------------------------------------------------------------------------------17. What are the arguements we normally use for Perl Interpreter Ans. -e for Execute, -c to compile, -d to call the debugger on the file specified, -T for traint mode for security/input checking -W for show all warning mode (or -w to showless warning)------------------------------------------------------------------------------------------------------------18. what is it meants by '$_'?Ans. it is a default variable which holds automatically, a list of arguements passed to thesubroutine within parentheses.-------------------------------------------------------------------------------------------------------------19. How to connect to sql server through Perl?Ans. We use the DBI(Database Independent Interface) module to connect to anydatabase. use DBI; $dh = DBI->connect("dbi:mysql:database=DBname","username","password"); $sth = $dh-> prepare("select name, symbol from table"); $sth->execute(); while(@row = $sth->fetchrow_array()){ print "name =$row[0].symbol= $row[1]; } $dh->disconnect

Activity (247)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Karthika Vijayan liked this
bshirish liked this
Nathan Ma liked this
Piyali Das liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->