Need help with Perl, using perl 5 Exercise A3 What is the value of $x and $y aft
ID: 3600334 • Letter: N
Question
Need help with Perl, using perl 5
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++;
}
Explanation / Answer
Hi friend, I have answered firs four.
Please repost others in separate post.
$x = 4;
$x++; // incrementing x by 1, x = 5
$y += $x + 3; // y = x + 3 , 5 + 3 = 8
Ans: x = 5, y = 8
== operator of Perl converts the string to a number.
4 < "23A" : False
-14 < "-13" : False
"14" != 14 : False
0 >= "AB" : True
op1 <=> op2 this operator returns 1 if op1 is greater than op2, 0 if op1 equals op2, and -1 if op1 is less than op2.
1 <=> 7 : -1
2 <=> "H" : 1
4 cmp 7 : -1
"4" <=> undef : 1
"Hi" && 2 : True
"Hi" || 2 : True
"00" && 4 : True
"00" || "0" : True