[Omaha.pm] Test Questions

Dan Linder dan at linder.org
Sat Jan 3 19:36:06 PST 2009


I'll take a stab...though this really sounds like test questions copied
verbatim... :-\

On Fri, Jan 2, 2009 at 8:35 PM, <oak83 at cox.net> wrote:

> 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?
>

When I ran this snippet of code:
     printf ("len:%i\n", length(1+2+3));

I got back "1".  That sounds right since the perldoc.perl.org site says that
length "returns the length in *characters* of the value of EXPR"  Thus, the
math is done first (1+2+3) and results in 6.  That value is then converted
to a string ("6"), which has a length of 1.


> 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);
>

I had to double check the Perl.com perlop reference (
http://www.perl.com/doc/manual/html/pod/perlop.html), but the C precedence I
remembered from CS many years ago still holds.

Since "$b++" means "increment the $b variable AFTER returning it's current
value to the expression using it", and "++$c" means "increment $c and return
the new value to the expression."  Since the ++ are tightly bound to the
variable, the multiply doesn't affect the overall value, so the third
example:
     $c = $c + 1; $a = $b * $c; $b = $b + 1;
Is a different way to write it.


> 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


The third one.

I think that's enough for now.   I didn't see you have submitted a dozen
questions...  My initial instinct that these are test questions is feeling
more certain.

If this was some sort of a take-home test, how hard would it be to write a
small bit of code to test each one if you're not 100% sure? (That's what I
did on the $b++ * ++$c question...)

If this isn't a test, why not point us toward the source code you're
debugging and it might make more sense.

Dan

-- 
"Quis custodiet ipsos custodes?" (Who can watch the watchmen?) -- from the
Satires of Juvenal
"I do not fear computers, I fear the lack of them." -- Isaac Asimov (Author)
** *** ***** ******* *********** *************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20090103/9ba4e341/attachment.html>


More information about the Omaha-pm mailing list