Please upload a single PERL .pl file on eLearning: 1. Write code to do the follo
ID: 3737530 • Letter: P
Question
Please upload a single PERL .pl file on eLearning:
1. Write code to do the following using: a. Set the value of variable x to 100. b. Print the value of 2x + 5.
2. Write a script that generates two random numbers between -10 and 10 and if the numbers match then prints “Match Found” else prints “Different Numbers”. You can use $RANDOM to generate the random numbers.
3. Write a script to declare two scalar variables x and y, initialize them to some values, and compute sum of their squares.
4. Write a script to declare two list(array) variables x and y of length 3 each, initialize them to using numbers, compute a list that is the sum of these lists, and print the middle three elements of the resulting list.
5. Write a script to declare a hash variable x which contains 3 values and 3 keys, initialize values to names and keys to numbers.
6. Write a script using if…elsif…else to compare three words entered by the user and compare if any two match.
7. Write a script using the while loop construct that generates 100 randomly generated numbers between 0 and 99 and writes them out in a user specified filename.
8. Write a subroutine to generate two random numbers between -10 and 10 and compute sum of their squares.
Explanation / Answer
Hi friend, As per the chegg policy, Please post only 4 Parts of the Big Problem.
I have implemented first 4 Questions.
Please rate my answer if it helped you!!
Doing first 4
# 1
my $x = 100;
print("2*$x + 5 ");
#2
my $high = 10;
my $low = -10;
my $a = int(rand($high - $low) + $low);
my $b = int(rand($high - $low) + $low);
if ($a == $b) {
print("Match Found ");
}
else {
print("Different Numbers ");
}
#3
my $x = 9;
my $y = 5;
my $sqsum = $x*$x + $y*$y;
print("Sum of square of $x and $y = $sqsum ");
#4
my @a = (1,2,3);
my @b = (5,6,8);
my @c;
for my $i ( 0..$#a ) {
push @c, $a[$i] + $b[$i];
}
print(join(", ", @c) . " ");