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

Need help with Perl. Using Perl 5. Exercise A1 Show the result of the following

ID: 3599741 • Letter: N

Question

Need help with Perl. Using Perl 5.

Exercise A1

Show the result of the following expressions:

23 + "7" = 30

14 * "A23" = 0

3 ** 4 =

"Hello" . "4"

24 / 6 = 4

Exercise A2

Show the result of the following expressions:

"Hello UPerlE lovers" = Hello PERL lovers

"Is this a line or two " = Is this

a line

or two

'What is 'this' '

'What is this $x'

Exercise A3

What is the value of $x and $y after the following statements?
$x = 4;
$x++;
$y += $x + 3;

Exercise A4

Which of the following expressions evaluate to true, and which evaluate to false?

4 < "23A"

-14 < "-13"

"14" != 14

0 >= "AB"

Exercise A5

What is the value of each of the following expressions?

1 <=> 7

2 <=> "H"

4 cmp 7

"4" <=> undef

Exercise A6

Which of the following expressions evaluate to true, and which evaluate to false?

"Hi" && 2

"Hi" || 2

"00" && 4

"00" || "0"

Exercise A7

The following statements set the values:

$x = 3;

$y = 0;

$z = -4;

Then, which of the following expressions evaluate to true, and which evaluate to false?

!( $x < $y ) = True

!( $x >= $y ) False

!( (4 + 5 * $y) >= $z -2 ) && ( $z - 2 )

!($x) && !($y) || !($z)

Exercise A8

Code a single statement, which uses the && operator, and produces the same results as this code:

if ( $x < 10 )

    {

    $x++;

    }

Exercise A9

Code a single statement, which uses the || operator, and produces the same results as this code:

unless ( $x < 10 )

    {

    $x++;

    }

Programming problems

Problem A10

Write a program that reads in three numbers:
Ask the user to input a decimal number as the first number.
Ask the user to input an octal number without the leading 0 as the second number.
Ask the user to input a hexadecimal number without the leading 0X as the third number.
Convert each number to decimal.
Print the following output, with description of each number:
Print the decimal value of the first number.
Print the octal and then the decimal value of the second number.
Print the hexadecimal and then the decimal value of the third number.
Use the following test data, in order: 1234 123 12

Problem A11

In this problem, do not use a loop.
Write a program that reads one string and prints it as many lines as its length with each copy on a separate line (The should not he considered when calculating the length).
For example, if the string is "world", the output should be as shown below (the length is 5):

world

world

world

world

world

Problem A12

Write a program that has a long string given which contains at least three 'e'
The program finds the positions of the first, second, and third "e" in the string and prints the results.
Test the program with the data:
$string = 'elephants eat a large quantity of food';

Problem A13

Write a program that has a long string given.
The program extracts the first five characters and the last five characters. and prints the results.
Test the program with the data:
$string = 'elephants eat a large quantity of food';

Problem A14

Write a program that, given three strings, uses string comparisons to select and print the smallest in ASCII sort order. Do not use the sort function.

Problem A15

Write a program that, given an integer between 1 and 12, prints the corresponding month of the year (January, February, ...).

Problem A16

Write a program that, given a floating-point number, prints the number rounded to two digits.
For example. 14.334 will be rounded to 14.33 but 14.336 will be rounded to 14.34.

Explanation / Answer

#!/usr/bin/perl
print 23 + "7", " ";   #23 + 7 = 30.
print 14 * "A23", " ";   #This will evaluate to 0.
print 3 ** 4, " ";       #3 powered 4 times, will be 81.
print "Hello" . "4", " ";   #4 will be appended to Hello.
print 24 / 6, " ";           #24 / 6 will be evaluated to 4.

print "Hello UPerlE lovers", " ";   #Hello PERL lovers ()
print "Is this a line or two ", " ";    #Is this
                                       #a line
                                       #or two
                                       # means a new line. So, for every ' ' will move to new line.
#'What is 'this' '   This will print the string What is this inside single quotes, and also, this inside single quotes.
print "'What is 'this' '", " ";
#'What is this $x'       This will print the value in the variable x.
$x = 10;
print $x, " ";

$x = 4;  
$x++;   #x value is incremented.
$y += $x + 3;   #y = 5 + 3 = 8.
print $y;

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