6. print (1+2)+4,"\t";
print +(1+2)+4;
ANS: 3 7
7. my
$a = 'Alien'; $a = $a + 1;
my
$b = 'Alien'; $b += 1;
my
$c = 'Alien'; $c++;
print join ", ", ( $a,
$b, $c );
ANS: 1,1,Alieo0
8. use strict;
my
$a = 'sz';
my
$b = 'sz';
print ++($a)x2,",
" ,++$b,", ", $b++;
ANS: tata, tb, ta
9. use strict;
use warnings;
my $var = 100;
my @var =
qw(aaa bbb ccc);
my @arr =
("AA", @var, "BB", "CC", ("dd",
"ee"), $var);
print scalar
@arr;
ANS: 9
10. $\ =
"\n"; # OUTPUT RECORD SEPARATOR $ORS
$, = ",
"; # OUTPUT FIELD SEPARATOR $OFS
@arr = (11, 22,
33, 44, 55);
print @arr;
#PRINTING WITH ENTERMARK AND COMMAS,
print '@arr';
#NO USE VARIABLE. PRINTING AS IT IS.
print
"@arr"; #NO USE OF FIELD SEPARATOR.
ANS: 11, 22, 33, 44, 55
@arr
11
22 33 44 55 #INCLUDING ENTERMARK
11. $\="\n";
my %systems =
(
languages
=> [ "Perl", "Python" ],
OS => [
"Windows", "Linux", "Mac" ],
DBMS => [
"MySQL", "Oracle", "Postgre SQL" ],
);
ANS:
print
$systems{OS}[1]; #For Linux
12. $\="\n";
my @arrays = (
[ "one", "two", "three" ],
[ 4, 5, 6, 7
],
[
"seven", 8,"Nine",10 ]
);
print
$arrays[2]->[2]; #Print Nine
13. $, = ",
";
%has = (a, AA,
b, BB, c, CC, d, DD);
print @has{b,
a, d, b, c};
ANS: BB, AA, DD, BB, CC
14. $, = ",
";
($a, @b, $c) =
(aa, bb, cc);
print
"$a, @b, $c";
ANS: aa, bb cc
15. my $string =
'Jassi';
print ref($string);
ANS: Empty
16. $\ =
"\n";
$a = (aa, bb,
cc);
print $a;
($a) = (aa,
bb, cc);
print $a;
ANS: aa
cc
17. my @a = (0, 1,
2);
$#a = 0;
my $size = @a;
print $size;
ANS: 1
18. $\ =
"\n";
$, = ",
";
@arr = (aa,
bb, cc, dd, ee);
print
">>@arr<<";
print @arr;
ANS: >>aa bb cc dd ee<<
aa, bb, cc, dd, ee
19. my %hash =
(One => 1, Two => 2);
my $count = 0;
while (my ($key, $value) = each(%hash)) {
$count++ if $value == keys(%hash);
}
print "$count\n";
ANS: Loop will not complete.
20. my $val = '0';
if ($val) {
print
"true\n";
} else {
print
"false\n";
}
True or False
ANS: False
21. @arr = (11,
22, 33, 44, 55);
print @arr;
#PRINTING WITH ENTERMARK AND COMMAS,
print '@arr';
#NO USE VARIABLE. PRINTING AS IT IS.
print
"@arr"; #NO USE OF FIELD SEPARATOR.
ANS: 11, 22, 33, 44, 55
@arr
11 22 33 44 55
22. my %hash;
$hash{undef} =
undef;
$hash{''} =
'';
$hash{0} = 0;
my $keys =
keys(%hash);
print $keys;
ANS: 3
23. my $var = 100;
my @var =
qw(aaa bbb ccc); # Count 3
my @arr =
("AA", @var, "BB", "CC", ("dd",
"ee"), $var); #Count 6
print scalar
@arr; #Total Nine
ANS: 9
24. my $foo =
'150' | 105;
my $bar =
'150' | '105';
my $magic =
"j p \n" ^ " a h";
print
"$foo,$bar,$magic\n"; #255,155,JAPH
print ~55
& 0xff ,"\n"; # 200
ANS: 255,155,JAPH
200
Comments
Post a Comment