Perl

Perl Interview questions for freshers and experienced

Sending
User Rating 5 (7 votes)

Here is the collection of most frequently asked Perl interview questions.

perl logoPerl Basics

  1. What is CPAN? Its uses?
  2. What does “use strict” , “use vars” , “no vars” mean?
  3. Difference b/w use and require?
  4. What do the symbols $ @ and % mean when prefixing a variable?
  5. What purpose does each of the following serve: -w, strict, -T ?
  6. Explain the use of do, require, use, import
  7. Use of our, my and local?
  8. Use of ref function
  9. What are STDIN,STDOUT and STDERR?.
  10. @INC and %INC
  11. How you can invoke shell command? Hint: system(), backtick, exec() in details
  12. What is the exact difference between system() and exec() (similar to question no 11)
  13. Error handling using eval
  14. Print the array @arr in reversed case-insensitive order.
  15. There are two types of eval statements i.e. eval EXPR and eval BLOCK. Explain them.
  16. Autovivification (very rarely)
  17. Questions on hash and hash reference
    1. Sort a hash by values
    2. Length of a hash
    3. How to refer a hash and how to dereference it
    4. Nesting of hash
  1. Chomp and chop
  2. Explain qw,qq,qx (what’s its use, when to use)
  3. What are the different ways to concatenate strings in Perl
  4. Functions on array: Push, pop, shift, unshift, join, split, splice
  5. Different hash functions like each, keys, values, exists, delete
  6. Numeric and string sorting
  7. How to set Environment variables in Perl (Hint: %ENV)
  8. Use of map and grep functions in Perl
  9. What is the difference between die and exit in perl
  10. Array with repeating digits. Sort and print digits with no of counts. Ex: @arr = (1,2,4,6,3,1,2,6,8,3,4,9,1,2,4). Output should be @arr = (1,1,12,2,2,3,34,4,4,6,6,8,9) ). You can’t use hash feature. Think about optimization too.
  11. Decimal to binary (program)
  12. How to find which method is being invoked or being called in Perl and in which method you are currently? Hint: caller()
  13. Explain the use of caller and wantarray function?
  14. How will you find line number, package and a file name in Perl? (Hint: __FILE__, __LINE__, __PACKAGE__)
  15. How to install a Perl Module from CPAN
  16. Pass an array to subroutine and get t as array ref in sub. Hint: subroutine prototype. Ex: sub subname(\@)
  17. You have two arrays. Say @arr1 = (1,2,5,6) and @arr2 = (3,4) We need to put the element of @arr2 at @arr1 in such a way that @arr1 would become @arr1= (1,2,3,4,5,6) without using third array.  Hint: use splice function
  18. Inbuilt special variable like $!, $? Etc
  19. Piping in and piping out in Perl
  20. How to implement stack and queue in Perl?
  21. How to find the list of installed modules in Perl?
  22. Use of BEGIN and END block.
  23. Simulate the behaviour of ‘use lib’ pragma using BEGIN block.

File Handling in Perl

  1. File Testing. Binary or text, size, accessed like –e, -f, -a, -c –m etc
  2. Use of the special file handle _. (Note : its just _ not $_). Using this can significantly improve performance in many cases.
  3. Syntax for opening, appending, reading, writing files
  4. How to assign File handle into an array instead of using while loop?
  5. How to delete a file?
  6. How to copy or move a file?
  7. What the various file permissions (flags) in Perl?
  8. Given a file, count the word occurrence (case insensitive)
  9. Displaying file contents using hash in Perl

Web based & Perl CGI

  1. What do you know about CGI.pm?
  2. How to set sessions and cookies and how to implement in Perl?
  3. How to display JSON based output
  4. Why two \n in print “Content-type: text/html \n\n”;

Database oriented

  1. How to connect database using DBI http://perlmeme.org/tutorials/connect_to_db.html
  2. What are the ways you know to get records from the table (fetchrow_hashref/arrayref)

Object Oriented Perl

  1. Diff b/w module and package
  2. Diff b/w class and package (rarely asked though )
  3. How do you call any subroutine in object oriented fashion? Hint: bless operator
  4. Use base, EXPORT, EXPORT_OK
  5. Difference between ISA and EXPORT
  6. Use Base related questions
  7. Use of AUTOLOAD function.

Regular Expression in Perl

  1. IP Address validation
  2. Email id Validation
  3. More than one @ is there. Give regex to store username and domain name after encountering last @ (Last @ will be the splitting point and more than one special characters can be there )
  4. What are the uses of different modifiers
  5. Group, range, meta-character etc
  6. m, s, tr
  7. Replace the last ‘x’ in a string with ‘ax’ in one regex. Example : abcxdefgxgaxa should become abcxdefgxgaaxa
  8. Perl regular expression is greedy. Can you explain it with one example?
  9. Can you check palindrome condition using regular expression in perl? (Hint: regex doesn’t support recursion or counting facility )

Perl One Liner

  1. What is Perl one liner and where you will use it?
  2. What are the different options in Perl one Liner. Explain in details
  3. Add a blank line before every line.
  4. Remove blank lines form a file.
  5. Print the total number of lines in a file (emulate wc -l).
  6. Print the number of non-empty lines in a file.
  7. What option you will use to check syntax only without executing it?
  8. Which option is meant to enable all warnings or disable all warning inspite of using use warning or no warnings respectively?

Share your Thoughts