Home / Interview / Perl :: General Questions

Interview :: Perl

61)

Explain regular expression in Perl?

A regular expression is a string of characters that defines a specific pattern.

There are three regular expression operators inside Perl:

  • Matching regular expression operator, m//
  • Substitute regular expression operator, s///
  • Transliterate regular expression operator, tr///

62)

Explain split function in Perl?

Perl split function splits a string at specified delimiter pattern like -, /,:, etc. By default, whitespace is assumed as delimiter pattern if nothing is specified.

63)

Explain join function in Perl?

Perl joins function joins symbol or character in between or afterward each element of an array.

64)

Explain subroutine in Perl?

Perl subroutine lets you reuse code in your program. They accept arguments, perform their operation and return the values. A subroutine is declared with 'sub' keyword before its name. In Perl, function and subroutine are used interchangeably.

65)

How to access parameters passed to a subroutine in Perl?

Parameters are accessed inside a subroutine using special array @_. Hence, the arguments will start with $_[0], $_[1], $_[2], $_[3] and so on.

66)

Explain the use of 'my' keyword in Perl?

The 'my' keyword restricts a variable to a particular region in which it can be used and accessed. Outside this region, this variable can't be used.

67) Explain the difference between declarations of 'my' and 'local' variable scope in Perl?

Variables declared with 'my' keyword live within a code block and can't get its visibility inherited in the functions called within that block.

Variables declared with 'local' keyword live within a code block and got its visibility in the functions called within that block.

68)

Explain the default scope of variables in Perl?

By default, all variables in Perl are global variables unless they are locally defined. They can be accessed from anywhere in a program.

69) What is lexical variable in Perl?

Lexical variables are created using 'my' keyword in Perl. They are private variables.

70)

How will you create a file in Perl?

To create a file in Perl, '>' sign is used before the file name. It will create a new file.