SPUG: PERL technical interview

DeRykus, Charles E charles.e.derykus at boeing.com
Mon Jan 23 05:47:17 PST 2006


On Sat, Jan 21, 2006 at 11:04:59PM -0800, 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)));
> which seems unfair to me. I mean, if they're going to expect me to use

> Perl, I should be able to use Perl, not use Perl in a particular way 
> they mandate (they seem to always want something that uses substr).

YST >> So they want something like

YST >> substr$string,0,0,substr$string,-1,1,""for 1..length$string

Cool. If I look up substr's 4th arg and run Deparse, a self-consuming
comes into focus:

$ perl -MO=Deparse,-p -e 'substr$string,0,0,substr$string,-1,1,""for
foreach $_ (1 .. length($string)) {
    substr($string, 0, 0, substr($string, (-1), 1, ''));
-e syntax OK

Too bad interviews aren't Jeopardy-style :)

Charles DeRykus

More information about the spug-list mailing list