Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Perl identifiers that hold a single value (number or string) should begin with a

ID: 3812540 • Letter: P

Question

Perl identifiers that hold a single value (number or string) should begin with a

$

#

@

%

Suppose a Perl program is started from the bash command line on a Linux system as below.

./p1.pl A B C D

Which of the following variables contains "A"?

$ARGV[-1]

$ARGV[0]

$ARGV[1]

$ARGV[2]

What is the difference between eq and =~i in Perl?

eq looks for equality and =~ means pattern matching

=~ looks for equality and eq means pattern matching

Both operators are equivalent

There is no eq operator in Perl

Perl supports matching against regular expressions.

Which of the following functions can be used to divide a string into individual tokens in Perl?

convert

divide

split

tokenize

Consider the following Perl code fragment for the next two questions.

$line = "128.78.12.9";

($p1, $p2) = split('.', $line);

What does the variable $p1 contain after the code fragment completes execution?

128

78

12

9

What does the variable $p2 contain after the code fragment completes execution?

128

78

12

9

Perl statements must be terminated by

.

:

$

;

The Perl statement

open(FILE, $line):

opens a file for appending

opens a file for writing

opens a file for reading

opens a file for reading and writing

A while loop in Perl

always executes a fixed number of times

continues to iterate while the condition specified in the while statement remains false.

continues to iterate while the condition specified in the while statement remains true.

continues to iterate while there is a line in some file to read.

1)

$

2)

#

3)

@

4)

%

Explanation / Answer

Ans 1) 1 is the correct option.

Perl identifiers that hold a single value (number or string) should begin with a "$".

Example:- $string = "Harsh";

Ans 2) 2 is the correct option.

$ARGV[0], is the variables that contains "A" because $ARGV[0] is the first argument.

Ans 3) 1 is the correct option.

The difference between eq and =~i in Perl, eq looks for equality and =~ means pattern matching.

For Example:-

$s = "harsh ";
print "ok 1 " if $s =~ /^harsh$/;
print "ok 2 " if $s eq 'harsh';

Ans 4) True, Perl supports matching against regular expressions..

Ans 5) 3 is the correct option.

split functions can be used to divide a string into individual tokens in Perl.

Syntax of split function:- split REGEX,STRING.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote