Logo F2FInterview

Perl Interview Questions

Q   |   QA

i.) $ - The variable becomes a scalar variable which can hold one value only
ii.) @ - The variable becomes an array variable which can hold a list of scalar variables
iii.) % - The variable becomes a hash variable which stores values as key-value pairs

i.) –w
When used gives out warnings about the possible interpretation errors in the script.

ii.) Strict
Strict is a pragma which is used to force checks on the definition and usage of variables, references and other barewords used in the script. This can be invoked using the use strict command. If there are any unsafe or ambiguous commands in the script, this pragma stops the execution of the script instead of just giving warnings.

iii.) -T.
When used, switches on taint checking which forces Perl to check the origin of variables where outside variables cannot be used in system calls and subshell executions.

a.) Subroutine

Subroutines are named blocks of code that accept arguments, perform required operation and return values. In PERL, the terms subroutine and function are used interchangeably. Syntax for defining subroutine: sub NAME or sub NAME PROTOTYPE ATTRIBUTES to be specific where prototype and attributes are optional. PROTOTYPE is the prototype of the arguments that the subroutine takes in and ATTRIBUTES are the attributes that the subroutine exhibits.

b.) Perl one-liner

One-liners are one command line only programs (may contain more than one perl statements) that are used to accomplish an operation. They are called so because the program can be typed and executed from the command line immediately.
Eg:
# run program, but with warnings
perl -w my_file
# run program under debugger
perl -d my_file

c.) Lists

Lists are special type of arrays that hold a series of values. Lists can either be explicitly generated by the user using a paranthesis and comma to separate the values or can be a value returned by a function when evaluated in list context.

d.) iValue

An ivalue is a scalar value that can be used to store the result of any expression. Ivalues appear in the left hand side of the expression and usually represents a data space in memory.
Situation: You want to concatenate strings with Perl. How would you do that?

By using the dot operator which concatenates strings in Perl.
Eg. $string = “My name is”.$name

- Use use the libwww-perl library, LWP.pm
- #!/usr/bin/perl
use LWP::Simple;
$url = get 'http://www.DevDaily.com/';

Perl supports access to all of the major database systems through a number of extensions
provided through the DBI toolkit, a third-party module available from CPAN. Under Windows you can use either the DBI interfaces or the Win32::ODBC toolkit, which provides direct access to any ODBC-compliant database including SQL Server database products.
Using DBI:
use DBI;
my $dbh = DBI->connect(DSN);
Using ODBC:
Use Win32::ODBC;
$database = new Win32::ODBC("DSN" [, CONNECT_OPTION, ...]);

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: