In this article, we explored a range of topics in PERL programming. Starting with an introduction, we discussed question direction to ensure clarity, followed by an in-depth analysis of questions and answers across three insightful pages. We examined the differences between the my, local, and our keywords, highlighting their functionalities. Additionally, we reviewed reserved variables in PERL, explaining their significance and usage, and delved into reserved variables for arguments, showcasing their role in parameter passing. This article provides valuable insights into these essential PERL concepts.
In this article we will discuss some popular interview questions in PERL.
In this article, we explored a range of topics in PERL programming. Starting with an introduction, we discussed question direction to ensure clarity, followed by an in-depth analysis of questions and answers across three insightful pages. We examined the differences between the my, local, and our keywords, highlighting their functionalities. Additionally, we reviewed reserved variables in PERL, explaining their significance and usage, and delved into reserved variables for arguments, showcasing their role in parameter passing. This article provides valuable insights into these essential PERL concepts.
In this article we will discuss some popular interview questions in PERL.
1. #!/usr/bin/perl -w : What does the -w means ?
It means that per interpreter will issue warning wherever applicable during code execution.
2. Are the Variables in PERL Case Sensitive ?
Yes ! Perl is Case-Sensitive, i.e. $var is a completely different variable than $VAR.
3. How we can do the single and multi line comment in PERL ?
# is a single line comment .
=cut ends the Multi Line comment
8. What are the data types in PERL ?
Any thing an be assigned in the value of a variable :
$pi = 3.14159265; # is a "real" number
$animal = "Camel"; # is a string
$ab = $a * $b; # an mathematical operation
$out = `pwd`; # output from a command stored in $out
9. State the difference among – my,local,our
our $bar; # declares $Foo::bar for rest of lexical scope
$bar = 20;
package Bar;
our $bar = 30; # declares $Bar::bar for rest of lexical scope
print $bar; # prints 30
our $bar; # emits warning but has no other effect
print $bar; # still prints 30
10. What are the Reserved Variables in PERL ?
$_ The default input and pattern-searching space. It is an global variable.
The following functions use $_ as a default argument:
abs, alarm, chomp, chop, chr, chroot, cos, defined, eval, evalbytes, exp, fc, glob, hex, int, lc, lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, printf, quotemeta, readlink, readpipe, ref, require, reverse (in scalar context only), rmdir, say, sin, split (for its second argument), sqrt, stat, study, uc, ucfirst, unlink, unpack.
The pattern matching operations m//, s/// and tr/// (or, y///) in absence of =~ operator.
@_ Within a subroutine the array @_ contains the parameters passed to that subroutine. Inside a subroutine, @_ is the default array for the array operators pop and shift.
11. What is the multi line comment in PERL ?
=for starts the Multi Line comment
12. What values of a variable is considered as True & False in PERL ?
i. '0' Zero the number itself is false.
ii. The empty string ’ ’ and the string ’0’ are false.
iii. undef is false.
iv. Anything else is true.
13. How to execute a PERL program when you do not have permission of writing in a particular disk ?
perl -e 'print "\n Hello, world \n";'
14. What is the value by default associated to a scalar when is declared but not assigned ?
my $var; contain the value undef.
There is no separate type declaration for Integer, Real, Double/Float in PERL.
A my() declares the listed variables to be local (lexical) to the enclosing block, file, or eval. If more than one variable is listed, the list must be placed in parentheses.
A local() modifies the listed variables to be local to the enclosing block, file, or eval. If more than one value is listed, the list must be placed in parentheses.
An our() creates a package variable: It declares an alias for a package variable that will be visible across its entire lexical scope, even across package boundaries.
package Foo;
a & $b : Special package variables when using sort(). $a and $b don't need to be declared (using use vars, or our()) even when using the strict 'vars' pragma.
The default iterator variable in a foreach loop if no other variable is supplied.
%ENV : The hash %ENV contains your current system environment variables & their values can be manipulated by this hash/associative array.
@INC : The array @INC contains the list of places that the do EXPR, require, or use constructs look for their library files. It initially consists of the arguments to any -I command-line switches, followed by the default Perl library, probably /usr/local/lib/perl.
@ISA : Each package contains a special array called @ISA which contains a list of that class's parent classes, if any. This array is simply a list of scalars, each of which is a string that corresponds to a package name. The array is examined when Perl does method resolution, which is covered in perl obj.
$$ The process number of the Perl running your present script itself.
$0 Contains the name of the Perl program being executed.
$<digits> ($1, $2, ...) : Contains the sub-pattern from the corresponding set of capturing parentheses from the last successful pattern match, not counting patterns matched in nested blocks that have been exited already.
$& : The string matched by the last successful pattern match (not counting any matches hidden within a BLOCK or eval() enclosed by the current BLOCK).
$ARGV : Contains the name of the current file when reading from <>.
@ARGV : The array @ARGV contains the command-line arguments intended for the script.
Watch the Video for detailed explanation :