Perl Christmas Quiz 2009

Mike Whitaker mike at altrion.org
Tue Dec 1 08:03:19 GMT 2009


On 1 Dec 2009, at 07:44, Ruud H.G. van Tol wrote:

> Abigail wrote:
>> On Mon, Nov 30, 2009 at 06:24:12PM +0000, Chris Jack wrote:
> 
>>> 7) Write a one line program that takes a non-negative integer as an argument
>>> and prints the square root when the answer's an integer.
>>> 
>>> Restrictions: the perl line should be a regular expression.
>> Just a regular expression? Regular expressions don't print, so that would
>> be impossible.
> 
> Though perl can print itself:
> 
>  echo 169 | perl -ple'$_="the square root"if/^\d+$/'
> 
> (this is not an answer)

But this might be:

echo 169 | perl -pe '/(\d+)(?{ $_ = sqrt($^N)."\n" })/;'





More information about the london.pm mailing list