oysters2000
Programmer
please would someone please explain the following with the answer they get as i have different answers from two different books. They seem to contridict themselves. I will be writing my exam tomorrow and need to clear these up.
much appreciated.
What output is generated by the following code segmenet?
$i = 0;
while ($i++ <= 5)
{
print $i;
}
a. 2345
b. 12345
c. 012345
d. 123456
What output is generated by the following code segment?
"rubberband" =~ m/(b{1,3})/;
print $1;
a. b
b. bb
c. bbb
d. bberb
What output is generated by the following code segment?
@list = ("Alpha", "beta", "0123", "123");
@list = sort(@list);
print $list[1];
a. Alpha
b. beta
c. 0123
d. 123
What output is generated by the following code segment?
%hash = (1 => "Air",
2 => "Land",
3 => "Sea",
4 => "Space");
%hash = reverse(%hash);
foreach $key (keys(%hash))
{
if ($key =~ m/[^Space]{3,}/)
{
print $hash{$key};
}
Consider the following Perl code:
%myHash = (Alpha => "A",
Beta => "B",
Gamma => "G",
G => "Delta");
print($myHash{"Alpha"});
print(" ");
print($myHash{"Beta"});
print(" ");
reverse(%myHash);
print($myHash{"G"});
What is the output of this code?
a. Alpha Beta Gamma
b. Alpha Beta G
c. A B G
d. A B Delta
Consider the following Perl code:
%myHash = (Alpha => "A",
Beta => "B",
Gamma => "G",
G => "Delta");
print($myHash{"Alpha"});
print(" ");
print($myHash{"Beta"});
print(" ");
delete($myHash{"Alpha"});
delete($myHash{"Beta"});
delete($myHash{"Gamma"});
foreach $key (keys(%myHash))
{
print("$key $myHash{$key}");
}
What is the output of this code?
a. Alpha Beta A B G Delta
b. A B G Delta
c. A B A B G Delta
d. A B
Consider the following Perl code:
@myArray = ("Beta", "Gamma", "Alpha");
print("$myArray[1] ");
sort(@myArray);
print($myArray[1]);
What is the output of this code?
a. Gamma Gamma
b. Beta Gamma
c. Gamma Beta
d. Beta Alpha
Consider the following Perl code:
@myArray = ("A", "B", "C");
unshift(@myArray, pop(@myArray));
unshift(@myArray, pop(@myArray));
unshift(@myArray, pop(@myArray));
print("@myArray");
What is the output of this code?
a. No output is generated
b. A B C
c. C B A
d. C
}
a. 1
b. 2
c. 4
d. Space
What output is generated by the following code segment?
print (add(5, 7));
sub add
{
foreach $val (@_)
{
$total += $val;
print $val;
}
}
a. 5
b. 7
c. 12
d. 57
What output is generated by the following code segment?
print (add(3, 4));
sub add
{
for ($i = 0; $i < 2; $i++)
{
$total += $_[$i];
}
}
a. 2
b. 3
c. 4
d. 7
What output is generated by the following code segmenet?
$i = 0;
while ($i++ < 5)
{
print $i;
}
a. 2345
b. 12345
c. 012345
d. 123456
What output is generated by the following code segment?
$var = "Alpha";
package Beta;
$var = "Beta";
{
package Gamma;
$var = "Gamma";
package main;
}
print $var;
a. Alpha
b. Beta
c. Gamma
d. No output is generated
Consider the following module definition:
package Employee;
1;
sub new
{
my $object = {};
$object->{"name"} = $_[0];
$object->{"salary"} = $_[1];
$object->{"start_date"} = $_[2];
return bless $object;
}
What output is generated by the following code segment using the module defined above?
require Employee;
$jose = new Employee("Jose Martinez", 45500, "11/5/2001");
print $jose->{"name"};
a. name
b. jose
c. Jose Martinez
d. Employee
much appreciated.
What output is generated by the following code segmenet?
$i = 0;
while ($i++ <= 5)
{
print $i;
}
a. 2345
b. 12345
c. 012345
d. 123456
What output is generated by the following code segment?
"rubberband" =~ m/(b{1,3})/;
print $1;
a. b
b. bb
c. bbb
d. bberb
What output is generated by the following code segment?
@list = ("Alpha", "beta", "0123", "123");
@list = sort(@list);
print $list[1];
a. Alpha
b. beta
c. 0123
d. 123
What output is generated by the following code segment?
%hash = (1 => "Air",
2 => "Land",
3 => "Sea",
4 => "Space");
%hash = reverse(%hash);
foreach $key (keys(%hash))
{
if ($key =~ m/[^Space]{3,}/)
{
print $hash{$key};
}
Consider the following Perl code:
%myHash = (Alpha => "A",
Beta => "B",
Gamma => "G",
G => "Delta");
print($myHash{"Alpha"});
print(" ");
print($myHash{"Beta"});
print(" ");
reverse(%myHash);
print($myHash{"G"});
What is the output of this code?
a. Alpha Beta Gamma
b. Alpha Beta G
c. A B G
d. A B Delta
Consider the following Perl code:
%myHash = (Alpha => "A",
Beta => "B",
Gamma => "G",
G => "Delta");
print($myHash{"Alpha"});
print(" ");
print($myHash{"Beta"});
print(" ");
delete($myHash{"Alpha"});
delete($myHash{"Beta"});
delete($myHash{"Gamma"});
foreach $key (keys(%myHash))
{
print("$key $myHash{$key}");
}
What is the output of this code?
a. Alpha Beta A B G Delta
b. A B G Delta
c. A B A B G Delta
d. A B
Consider the following Perl code:
@myArray = ("Beta", "Gamma", "Alpha");
print("$myArray[1] ");
sort(@myArray);
print($myArray[1]);
What is the output of this code?
a. Gamma Gamma
b. Beta Gamma
c. Gamma Beta
d. Beta Alpha
Consider the following Perl code:
@myArray = ("A", "B", "C");
unshift(@myArray, pop(@myArray));
unshift(@myArray, pop(@myArray));
unshift(@myArray, pop(@myArray));
print("@myArray");
What is the output of this code?
a. No output is generated
b. A B C
c. C B A
d. C
}
a. 1
b. 2
c. 4
d. Space
What output is generated by the following code segment?
print (add(5, 7));
sub add
{
foreach $val (@_)
{
$total += $val;
print $val;
}
}
a. 5
b. 7
c. 12
d. 57
What output is generated by the following code segment?
print (add(3, 4));
sub add
{
for ($i = 0; $i < 2; $i++)
{
$total += $_[$i];
}
}
a. 2
b. 3
c. 4
d. 7
What output is generated by the following code segmenet?
$i = 0;
while ($i++ < 5)
{
print $i;
}
a. 2345
b. 12345
c. 012345
d. 123456
What output is generated by the following code segment?
$var = "Alpha";
package Beta;
$var = "Beta";
{
package Gamma;
$var = "Gamma";
package main;
}
print $var;
a. Alpha
b. Beta
c. Gamma
d. No output is generated
Consider the following module definition:
package Employee;
1;
sub new
{
my $object = {};
$object->{"name"} = $_[0];
$object->{"salary"} = $_[1];
$object->{"start_date"} = $_[2];
return bless $object;
}
What output is generated by the following code segment using the module defined above?
require Employee;
$jose = new Employee("Jose Martinez", 45500, "11/5/2001");
print $jose->{"name"};
a. name
b. jose
c. Jose Martinez
d. Employee