perl interview questions
Top perl frequently asked interview questions
just want to know what are the main differences among them? and the power of each language (where it's better to use it).
Edit: it's not "vs." like topic, just information.
Source: (StackOverflow)
How do I compare two strings in Perl?
I am learning Perl, I had this basic question looked it up here on StackOverflow and found no good answer so I thought I would ask.
Source: (StackOverflow)
When I run perl
, I get the warning:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
How do I fix it?
Source: (StackOverflow)
Can someone please help me? In Perl, what is the difference between:
exec "command";
and
system("command");
and
print `command`;
Are there other ways to run shell commands too?
Source: (StackOverflow)
I'm working on a Perl script. How can I pass command line parameters to it?
Example:
script.pl "string1" "string2"
Source: (StackOverflow)
I'm running 32 bit ActiveState 5.14.2 on Windows 7. I wanted to mess around with a git pre-commit hook to detect programs being checked in with syntax errors. (Somehow I just managed to do such a bad commit.) So as a test program I randomly jotted this:
use strict;
use warnings;
Syntax error!
exit 0;
However, it compiles and executes with no warnings, errorlevel is zero on exit. How is this valid syntax?
Source: (StackOverflow)
I seem to have come across several different ways to find the size of an array. What is the difference between these three methods?
my @arr = (2);
print scalar @arr; # First way to print array size
print $#arr; # Second way to print array size
my $arrSize = @arr;
print $arrSize; # Third way to print array size
Source: (StackOverflow)
I know what my
is in Perl. It defines a variable that exists only in the scope of the block in which it is defined. What does our
do? How does our
differ from my
?
Source: (StackOverflow)
How can I round a decimal number (floating point) to the nearest integer?
e.g.
1.2 = 1
1.7 = 2
Source: (StackOverflow)
I am trying to figure out a way of checking for the existence of a value in an array without iterating through the array.
I am reading a file for a parameter. I have a long list of parameters I do not want to deal with. I placed these unwanted parameters in an array @badparams
.
I want to read a new parameter and if it does not exist in @badparams
, process it. If it does exist in @badparams
, go to the next read.
Source: (StackOverflow)
I have a file which contains several thousand numbers, each on it's own line:
34
42
11
6
2
99
...
I'm looking to write a script which will print the sum of all numbers in the file. I've got a solution, but it's not very efficient. (It takes several minutes to run.) I'm looking for a more efficient solution. Any suggestions?
Source: (StackOverflow)
I have tried:
$var = false;
$var = FALSE;
$var = False;
None of these work. I get the error message
Bareword "false" not allowed while "strict subs" is in use.
Source: (StackOverflow)
I understand one uses the "bless" keyword in Perl inside a class's "new" method:
sub new {
my $self = bless { };
return $self;
}
But what exactly is "bless" doing to that hash reference ?
Source: (StackOverflow)
I have Perl script and need to determine the full path and filename of the script during execution. I discovered that depending on how you call the script $0
varies and sometimes contains the fullpath+filename
and sometimes just filename
. Because the working directory can vary as well I can't think of a way to reliably get the fullpath+filename
of the script.
Anyone got a solution?
Source: (StackOverflow)