Re: New Perl Quiz of the Week mailing list perl-qotw

[email protected] (Andrew Savige)
Newsgroups perl.golf
Message-ID <[email protected]>
En op zeventien oktober tweeduizendtwee sprak (-ugene:
> So what rule are they using to score their solutions?
I don't know. The arbiter in this game is mjd and he has yet to
deliver a verdict. If I were arbiter, however, I would declare the
winner without hesitation as Eugene van der Pijll, with (sic):

sub subst {
  my $a;
  join '', map {++$a%2 ? $_ : eval} split /(\$\d+)/, shift;
}

You can't help but admire all that lovely white space -- and, look!
he used shift instead of pop. Seeing (-ugene do that was almost as
surreal as watching `/anick favour the eccentric 'length' over the
normal 'y///c'.

If Brother van der Pijll is not declared the winner, I vote that we
declare war on the perl-qotw mailing list.

It may be too soon to start golfing this, but a more normal
interpretation of (-ugene's brilliancy is something like:

sub subst{join'',map--$|?$_:eval,split/(\$\d+)/,$_[$|=0]}

if you allow the subroutine to mangle $| (admittedly dubious).
Can anyone do better?

Original problem specification:
---------------------------------------------------------------------
Write a subroutine, 'subst', which gets a string argument, $s.  It
should search $s and replace any occurrences of "$1" with the current
value of $1, any occurrences of "$2" with the current value of $2,
and so on.

For example, if $1, $2, and $3 happen to be "dogs", "fish" and
"carrots", then

        subst("$2, $1 and $3")

should return

        "fish, dogs, and carrots"
---------------------------------------------------------------------
Note: You should not mangle other stuff in the string, otherwise the
solution would be a trivial subst{eval"\"@_\""}.

/-\



http://careers.yahoo.com.au - Yahoo! Careers
- 1,000's of jobs waiting online for you!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.