[Omaha.pm] Test Questions

oak83 at cox.net oak83 at cox.net
Fri Jan 2 18:35:37 PST 2009


Gents, I need some clarification on these if you do not mind? I am shaky on these. I will try to write these and see what happens. Any input is greatly appreciated.

What is the value of the expression length(1+2+3) ?  5 or 6 or Am I off base?

1

5

6

0

The expression $a = $b++ * ++$c has the same effect on $a, $b, and $c as which of the following? Think it is the 2nd one?

$a = $b * $c;

$a = ($b + 1) * ($c + 1);

$c = $c + 1; $a = $b * $c; $b = $b + 1;

$a = $b * ($c + 1);

When is this logical expression true: lc($a) eq $a ?   Think it is the 3rd one?

Never

Always

When $a contains no uppercase letters

When $a contains no lowercase letters

What is the result of @a = split(" ", "Hello, do you Yahoo?");? Empty for now?

@a contains "Hello, do you Yahoo?".

@a contains ("Hello", "do", "you", "Yahoo").

@a contains an empty list

@a contains ("Hello,", "do", "you", "Yahoo?").
When reading the contents of a directory, you can use code like this - $entry = readdir(DIRHANDLE); - in a loop to read the directory entries one at a time. How can you read all the directory entries in one call? Not how I would do it? I would chdir and open it

It's not possible.

Use a different call: @entries = readdirentries(DIRHANDLE);.

Pass an array variable to readdir(): readdir(DIRHANDLE, @entries);

Use readdir() in a list context: @entries = readdir(DIRHANDLE);.

What is accomplished by passing a subroutine name to sort() - for example: sort my_subroutine (@array)? Third One

The subroutine is called instead of sort.

The subroutine affects the sort order by defining how to compare elements.

The subroutine is called for each element before sorting begins.

The subroutine is called for each element after sorting ends.

If $a contains the string "Hello world", what is the result of this regular expression substitution: $a =~ s/^(.*)\s(.*)$/\2\1/ ? 2nd or 3rd one?

"Helloworld"

"world Hello"

"worldHello"

"Hello world"

My array @a contains a list of words. How can I create a new list containing only those words from @a that begin with capital letters? 2 or 4


   1.

      @a =~ m/^[A-Z]/;

      split(/^[A-Z]/, @a);

      @a =~ s/\s[^A-Z]\S*\s/ /;

      grep(/^[A-Z]/, @a);
   2. Using Perl's object-oriented features, what does this code do: $computer = Personal::Computer->new(); $computer->reboot();. 4th one?

      Reboots your computer.

      Calls a class method reboot() on the class Personal::Computer.

      Creates a new method named reboot().

      Creates an object of class Personal::Computer and calls its reboot() method.

What's the difference between these two ways of running an external program named showmem: system("showmem");`showmem`;  ?
?

You can send data from the script to system("showmem"), but not to `showmem`.

You can run a graphical application with system(), but not with ``.

system("showmem") captures the output into a string in the Perl script, while `showmem` sends its output to stdout.

system("showmem") sends its output to stdout, while `showmem` captures the output into a string in the Perl script.

I have two hash variables, %a and %b. I wish to create an array @a with elements containing references to these two hashes. How do I do it?  4th one

@a = (\%a, \%b);

@a = (%a, %b);

@a = (%%a, %%b);

@a = (%$a, %$b);


What does this do: open(PIPE, "| sum | sort");?  ?

Adds columns of numbers written to the PIPE file handle and sorts the results.

Runs two external programs named sum and sort. The script can send data to sum by writing to PIPE, sum's output is read by sort, and sort's output goes to stdout.

Runs two external programs named sum and sort. The input to sum comes from stdin, sum's output is read by sort, and the script can read sort's output from the PIPE file handle.

Runs two external programs named sum and sort. The script sends data to sum by writing to the PIPE file handle. After sum stops running, the script sends data to sort by writing to the PIPE file handle.


More information about the Omaha-pm mailing list