SPUG: PERL technical interview

Creede Lambard creede at penguinsinthenight.com
Mon Jan 23 17:33:00 PST 2006


On Sun, Jan 22, 2006 at 06:22:09PM +1100, Jacinta Richardson wrote:
> 
> Creede Lambard wrote:
> > Come up with a good way to reverse a string. I get asked that about two out
> > of three interviews, it seems like. Oh, and no one seems to like 
> > 
> >   print join ('', reverse( split (//, $string)));
> 
> What's wrong with:
> 
> 	print scalar reverse $string;
> 

Not a thing if it works as advertised :)

> ?  It's much less complicated.  

Sez you. :) I have trouble remembering contexts sometimes, but I have no
trouble remembering the join-reverse-split construction. It may also come
under the heading of expanding your code to improve readability.

I think part of the problem is that I am often interviewed by C coders who
are used to thinking in terms of reversing an array of chars with a loop
rather than with a single command. These same people are often surprised
that "unless" works as a keyword when I drop it into a piece of code as an
equivalent for "if not".


-- 
===================================================================
                               * .~. (   : Creede Lambard         :
 Never rush a miracle man.    . / V \  . :------------------------:
 You get lousy miracles.       /(   )\   : creede at              :
--------------------------------^^-^^----:     penguinsinthenight :  
 Linux. Reliable and free. Pick any two. :         dot com        :
===================================================================


More information about the spug-list mailing list