11.How many types of primary data structures in Perl and what do they mean?
The scalar: It can hold one specific piece of information at a time (string, integer, or reference). It starts with dollar $ sign followed by the Perl identifier and Perl identifier can contain alphanumeric and underscores. It is not allowed to start with a digit. Arrays are simply a list of scalar variables.
Arrays: Arrays begin with @ sign. Example of array:
my @arrayvar = (“string a”, “string b “string c”);
Associative arrays: It also frequently called hashes, are the third major data type in Perl after scalars and arrays. Hashes are named as such because they work very similarly to a common data structure that programmers use in other languages–hash tables. However, hashes in Perl are actually a direct language supported data type.
12.Which functions in Perl allows you to include a module file or a module and what is the difference between them?
- The method is used only for the modules (only to include .pm type file)
- The included objects are verified at the time of compilation.
- We don’t need to specify the file extension.
- loads the module at compile time.
- The method is used for both libraries and modules.
- The included objects are verified at the run time.
- We need to specify the file Extension.
- Loads at run-time.
suppose we have a module file as “Module.pm”
(will do the same)
13.How can you define “my” variables scope in Perl and how it is different from “local” variable scope?
$test = 2.3456;
my $test = 3;
print “In block, $test = $test “;
print “In block, $:: test = $:: test “;
print “Outside the block, $test = $test “;
print “Outside the block, $:: test = $::test “;
In block, $test = 3
In block, $::test = 2.3456
Outside the block, $test = 2.3456
Outside the block, $::test = 2.3456
The scope of “my” variable visibility is in the block only but if we declare one variable local then we can access that from the outside of the block also. ‘my’ creates a new variable, ‘local’ temporarily amends the value of a variable.
14.Which guidelines by Perl modules must be followed?
Below are guidelines and are not mandatory
The name of the package should always begin with a capital letter.
The entire file name should have the extension “.pm”.
In case no object oriented technique is used the package should be derived from the Exporter class.
Also if no object oriented techniques are used the module should export its functions and variables to the main namespace using the @EXPORT and @EXPOR_OK arrays (the use directive is used to load the modules).
15.How the interpreter is used in Perl?
Every Perl program must be passed through the Perl interpreter in order to execute. The first line in many Perl programs is something like:
The interpreter compiles the program internally into a parse tree. Any words, spaces, or marks after a pound symbol will be ignored by the program interpreter. After converting into parse tree, interpreter executes it immediately. Perl is commonly known as an interpreted language, is not strictly true. Since the interpreter actually does convert the program into byte code before executing it, it is sometimes called an interpreter/compiler. Although the compiled form is not stored as a file.
16.“The methods defined in the parent class will always override the methods defined in the base class”. What does this statement means?
The above statement is a concept of Polymorphism in Perl. To clarify the statement, let’s take an example:
@ISA = (X);
This program displays:
– In the above example, the foo() method defined in class Z class overrides the inheritance from class X. Polymorphism is mainly used to add or extend the functionality of an existing class without reprogramming the whole class.
17.For a situation in programming, how can you determine that Perl is a suitable?
If you need faster execution the Perl will provide you that requirement. There a lot of flexibility in programming if you want to develop a web based application. We do not need to buy the license for Perl because it is free. We can use CPAN (Comprehensive Perl Archive Network), which is one of the largest repositories of free code in the world.
18.Write syntax to add two arrays together in perl?
@arrayvar = (@array1,@array2);
To accomplish the same, we can also use the push function.
19.How many types of operators are used in the Perl?
+, – ,*
+= , -+, *=
Increment/ decrement operators:
==, !=, >, < , >=
&&, ||, !
20.If you want to empty an array then how would you do that?
We can empty an array by setting its length to any –ve number, generally -1 and by assigning null list
print “Array is not empty”;
print “Array is empty”;