PERL Flashcards

(45 cards)

1
Q

Who created Perl and when it was created?

A

Larry Wall created Perl in 1987

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does PERL stand for

A

Practical Extraction and Report Language” or Wall’s tongue-in-cheek
“Pathologically Eclectic Rubbish Lister”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When does Perl 1.0 launched

A

Perl 1.0 launched publicly on December 18, 1987, via Usenet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Perl 2 (1988)

A

upgraded the regular expression engine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Perl 3 (1989)

A

added support for binary data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Perl 4 (1991)

A

was mostly about better docs and synced with the first Programming Perl
book (the famous “Camel Book” co-authored with Randal L. Schwartz), which helpedspread the word

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What major features were introduced in Perl 5 (1994) that made it more powerful and modular?

A

References, modules, objects, and lexical variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is CPAN and when did it start?

A

The Comprehensive Perl Archive Network; it started in 1995 and created a thriving ecosystem of thousands of reusable modules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the relationship between Perl 6 and Raku?

A

Perl 6 was announced in 2000 as a fresh redesign. It shipped in 2015 and was officially renamed Raku in 2019 to distinguish it from Perl 5.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does Larry Wall mean by calling Perl the first “postmodern computer language”?

A

It focuses on programmer freedom rather than rigid rules, deliberately borrowing the best features from other languages while discarding what doesn’t work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the famous Perl motto and its common abbreviation?

A

“There’s more than one way to do it” (TMTOWTDI).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In what modern fields does Perl remain a reliable, mature tool today?

A

Legacy systems, bioinformatics, and scripting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does Perl’s data typing and declaration differ from languages like C or Java?

A

Perl does not require types to be declared ahead of time; it “figures things out as you go.” Declarations can be implicit or explicit (using my, our, or state).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the purpose of using use strict; in modern Perl code?

A

It enforces explicit declarations, helping to catch mistakes (like typos in variable names) early in the development process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Name the three main flavors of Perl variables and their corresponding sigils (prefix symbols).

A

$ for Scalars (single values: numbers, strings, or references)

@ for Arrays (ordered lists)

% for Hashes (key-value pairs/dictionaries)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How are Constants typically defined in Perl to ensure they are truly read-only?

A

By using the use constant module
(e.g., use constant PI => 3.14159;).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Besides the use constant module, what is the naming convention for variables intended to be constants?

A

Using UPPERCASE variable names
(e.g., $MAX_USERS = 100;), though this is a convention and does not technically prevent the value from being changed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the three built-in data types in Perl?

A

Scalars, Arrays, and Hashes. Everything else in Perl is built upon these three.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How does Perl handle different scalar values like integers, floats, and strings?

A

Perl has no separate types for them; it treats them all as Scalars and converts between them automatically as needed.

20
Q

Define Arrays in Perl and provide their starting index.

A

Ordered lists of scalars, indexed from 0 (e.g., @colors = (“red”, “blue”);).

21
Q

Define Hashes in Perl and the requirement for their keys and values.

A

Unordered key-value pairs; keys must be strings, while values are scalars (e.g., %person = (name => “Alice”);).

22
Q

How are User-defined types (Objects) created in Perl?

A

By “blessing” a reference (usually a hash) into a specific class or package using the bless function.

23
Q

Does Perl have native enumerated (enum) types?

A

No. Enumerated-like behavior is achieved through CPAN modules (like Enum) or by using constant hashes.

24
Q

What is the specific role of a Reference within the three built-in types?

A

A reference is considered a Scalar (a single item) that points to another data structure.

25
How are Strings handled in Perl, and what is the difference between 'single' and "double" quotes?
Strings are Scalars. Single quotes (' ') are literal, while double quotes (" ") allow for interpolation (e.g., "hello $name").
26
What is the definition of a List in Perl compared to an Array?
A list is a temporary sequence used in assignments or function calls (e.g., (1, 2, 3)), whereas an array is a stored variable.
27
How are Records typically represented in Perl?
Usually as a Hash (e.g., %student = (id => 123, name => "Bob");) or sometimes an array for fixed fields.
28
Since Perl has no built-in Set type, how is set membership usually implemented?
By using a Hash where the keys are the elements and the values are set to 1 (true).
29
What is a Reference in Perl, and why is it essential for complex structures?
A reference is a scalar that points to another variable or anonymous structure. It allows for nesting (e.g., arrays within hashes).
30
How are Trees and Graphs constructed in Perl?
Using nested references. Trees: Use a hash for the node and an array reference for children. Graphs: Use hashes of arrays or references to manage connections/cycles.
31
Provide a code example for a simple Tree node and how to add a child in Perl.
Node: $node = { value => 42, children => [] }; Add child: push @{$node->{children}}, { value => 10 };
32
How does Perl support Abstract Data Types (ADTs)?
Through references (usually to a hash) and object-oriented features like the bless function.
33
Provide a code example of blessing a hash reference into a class called "My::Queue".
my $obj = bless { name => "Queue" }, "My::Queue";
34
What is the goto LABEL; statement in Perl, and what is the modern best practice regarding its use?
It is an unconditional branch that jumps to a specific labeled line of code. It is considered bad style and should be avoided in modern Perl.
35
In Perl, what do the loop control statements next, last, and redo do?
next: Jumps to the next iteration. last: Exits the loop entirely. redo: Restarts the current iteration.
36
How do you write a postfix selection statement in Perl? (Provide an example)
print "Adult\n" if $age >= 18;
37
Two-way Selection in Perl
if ($x > 0) { print "Positive"; } else { print "Non-positive"; }
38
Two-way Selection in Perl
given ($day) { when ("Mon") { print "Start week"; } when ("Fri") { print "Weekend soon"; } default { print "Midweek"; } }
39
Iteration Pre-test (check first) in Perl
while ($i < 10) { print $i++; } until ($done) { ... } # runs while false
40
Iteration Post-test (run at least once): in Perl
do { print $i++; } while $i < 10;
41
Iteration Post-test (run at least once): in Perl
for (my $i = 0; $i < 5; $i++) { print $i; }
42
Control over Program execution foreach / for loops over lists in Perl
foreach my $item (@list) { print "$item\n"; }
43
Simple call/return in Perl
sub greet { return "Hello, $_[0]!"; } print greet("Horace");
44
45