Re: Perl Christmas Quiz 2009 Answers

2009-12-10 Thread Chris Jack

Leon wrote:
 Amelia points out that you got her name wrong. She was named by Larry

Don't think this gets you off the 1.5 pints you owe me.
 
Chris 
_
View your other email accounts from your Hotmail inbox. Add them now.
http://clk.atdmt.com/UKM/go/186394592/direct/01/


Re: Perl Christmas Quiz 2009 Answers

2009-12-09 Thread Paul Johnson
On Wed, Dec 09, 2009 at 01:20:54PM +, Chris Jack wrote:

 I think my answer to question 10 may cause controversy, but it is
 based on a careful reading of the sited webpage.

 10) What is the highest value of X that is a currently available, stable
 production release of perl 5.X?
 
 Answer: 8 see http://www.perl.com/download.csp

Unfortunately, I'm not sure that web page should be taken as
authoritative with respect to perl versions.

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net


Re: Perl Christmas Quiz 2009

2009-12-09 Thread Rallias UberNerd
On Mon, 30 Nov 2009 16:43:19 -0600, Dave Hodgkinson daveh...@gmail.com wrote:


 On 30 Nov 2009, at 18:24, Chris Jack wrote:


 Seeing as last year's quiz was mildly popular,

 Bonus question:

 How many people will be mildly irritated by starting a new thread
 with a Reply-to: to an existing one?


we just have to find out


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Mike Whitaker

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

 Abigail wrote:
 On Mon, Nov 30, 2009 at 06:24:12PM +, 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 rootif/^\d+$/'
 
 (this is not an answer)

But this might be:

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





Re: Perl Christmas Quiz 2009

2009-12-01 Thread Philip Newton
On Tue, Dec 1, 2009 at 09:03, Mike Whitaker m...@altrion.org wrote:

 (this is not an answer)

 But this might be:

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

Except it didn't follow the rules.

Cheers,
Philip
-- 
Philip Newton philip.new...@gmail.com


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Nicholas Clark
On Mon, Nov 30, 2009 at 02:52:21PM -0800, Avleen Vig wrote:
 On Nov 30, 2009, at 14:43, Dave Hodgkinson daveh...@gmail.com wrote:

 How many people will be mildly irritated by starting a new thread
 with a Reply-to: to an existing one?
 
 Answer: none. We stopped being petty in 1997 and grew up :p

List archive software doesn't (and can't) agree with you.

(and mail software could be better written to cope with user behaviour:
oh, I see you've changed the subject and deleted all the quoted text -
how about I automatically delete the References and In-Reply to headers
I was going to add?)

Nicholas Clark


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Abigail
On Mon, Nov 30, 2009 at 11:40:04PM +, Chris Jack wrote:
 
 
 Abigail abig...@abigail.be wrote
  
  On Mon, Nov 30, 2009 at 06:24:12PM +, 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.
 
 
 Pedant. Perl regular expressions allow execution of arbitrary code blocks - 
 which is why I put restrictions on which ordinary functions you were 
 allowed to use. The actual square root algorithm, however, should only use 
 the normal regular expression bestiary.


Do you mean by the latter that given a square number in unary, you want
a regexp determining the square root of that number, _without_ the use
of (?{ }) or (??{ })?

 
 I was going to point you towards my talk on Perl one-liners - which shows the 
 basic idea behind prime number checking and solving linear equations - but I 
 can't find any of the talks on the London Perl Mongers website... The 
 principal behind doing square root is similar but different.

Well, I guess you're looking for something like:

   /^(1+){length($1)-1}$/

which would be 'similar' but 'different' to my prime number checker. 
I'd be very interested to see how to do the C {length($1)-1} 
without (?{ })/(??{ }).



Abigail


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Dirk Koopman

Avleen Vig wrote:

On Nov 30, 2009, at 14:43, Dave Hodgkinson daveh...@gmail.com wrote:



On 30 Nov 2009, at 18:24, Chris Jack wrote:



Seeing as last year's quiz was mildly popular,


Bonus question:

How many people will be mildly irritated by starting a new thread
with a Reply-to: to an existing one?


Answer: none. We stopped being petty in 1997 and grew up :p



We did? Several of us must of missed that...


Re: Perl Christmas Quiz 2009

2009-12-01 Thread David Cantrell
On Mon, Nov 30, 2009 at 10:43:19PM +, Dave Hodgkinson wrote:

 Bonus question:
 
 How many people will be mildly irritated by starting a new thread
 with a Reply-to: to an existing one?

Not as many as will be mildly irritated at me replying but chopping out
the Reply-To.

-- 
David Cantrell | top google result for internet beard fetish club

  I remember when computers were frustrating because they did
  exactly what you told them to.  That seems kinda quaint now.
  -- JD Baldwin, in the Monastery


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Mark Zealey
 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.
 You are allowed to use the following functions/operators x, -,
  length, print plus any of the usual regular expression bestiary.

I'm pretty close but can't find a proper way to go to the previous capture 
group. eg the following works as much as you care to extend it:

(a x $ARGV[0]) =~ /^
(a)
( (a\g{-3})\g{-3} )?
( (a\g{-3})\g{-3} )?
( (a\g{-3})\g{-3} )?
( (a\g{-3})\g{-3} )?
( (a\g{-3})\g{-3} )?
( (a\g{-3})\g{-3} )?
$
(?{print length $+})
 /x;

However the obvious solution of using ( (a\g{-3})\g{-3} )* doesnt work as the 
capture buffers arn't updated on each match; and I can't manage to get the 
newer recursive syntax of (?-X) working properly. This would be worse anyway 
because then you could only go up to 50*50 before you get killed for deep 
recursion. The must be a way perhaps using the (?| syntax to get the capture 
buffers updated each time round?

Any thoughts?

Mark


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Mark Morgan
I recall that as part of technical test I took for a previous role, to
try and interpret and determine what it did.  Quite cool, but the
coolness was definitely exceeded by it's evilness... :)

Mark.

On Tue, Dec 1, 2009 at 11:26 AM, Abigail abig...@abigail.be wrote:
 which would be 'similar' but 'different' to my prime number checker.
 I'd be very interested to see how to do the C {length($1)-1} 
 without (?{ })/(??{ }).


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Matt Sergeant
On Mon, 30 Nov 2009 18:24:12 +, Chris Jack wrote:
 1) Without running it to check, what does the following program output?
 
 
 my %a = (3,2,1,0);
 
 
 for my $b (sort values %a) {
 $b += 4;
 }
 
 
 print $a{1} . \n;

Bizarrely enough, on both my Snow Leopard machines (default perl 
install) this outputs: 4D

Nice bug there.

Matt.

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Matt Sergeant
On Tue, 1 Dec 2009 11:23:09 -0500, Matt Sergeant wrote:
 On Mon, 30 Nov 2009 18:24:12 +, Chris Jack wrote:
 1) Without running it to check, what does the following program output?
 
 
 my %a = (3,2,1,0);
 
 
 for my $b (sort values %a) {
 $b += 4;
 }
 
 
 print $a{1} . \n;
 
 Bizarrely enough, on both my Snow Leopard machines (default perl 
 install) this outputs: 4D
 
 Nice bug there.

Ah. It's the D from ^D. Shitty terminal.

Matt.

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Randal L. Schwartz
 Matt == Matt Sergeant mserge...@messagelabs.com writes:

Matt On Mon, 30 Nov 2009 18:24:12 +, Chris Jack wrote:
 1) Without running it to check, what does the following program output?
 
 
 my %a = (3,2,1,0);
 
 
 for my $b (sort values %a) {
 $b += 4;
 }
 
 
 print $a{1} . \n;

Matt Bizarrely enough, on both my Snow Leopard machines (default perl 
Matt install) this outputs: 4D

Matt Nice bug there.

Lemme guess.  You did this:

$ perl
... type program in here ...
^D (control D)

The D is from your control D.

Common misconception.

If that *wasn't* it, let me know, so I can be perplexed. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Dermot
2009/12/1 Matt Sergeant mserge...@messagelabs.com:
 On Tue, 1 Dec 2009 11:23:09 -0500, Matt Sergeant wrote:
 On Mon, 30 Nov 2009 18:24:12 +, Chris Jack wrote:
 1) Without running it to check, what does the following program output?


 my %a = (3,2,1,0);


 for my $b (sort values %a) {
     $b += 4;
 }


 print $a{1} . \n;

 Bizarrely enough, on both my Snow Leopard machines (default perl
 install) this outputs: 4D

This is one of those situation where I should keep quiet to avoid
showing my ignorance but I can't help myself.

My first impression was that it would be 4. However, without running
it, I would say 0 on the basis that $b is scoped within the loop and
(not sure about this point) is a copy of the value in $a{1}.

I await the flak.
Dp.



Re: Perl Christmas Quiz 2009

2009-12-01 Thread Philip Newton
On Tue, Dec 1, 2009 at 17:52, Dermot paik...@googlemail.com wrote:
 (not sure about this point) is a copy of the value in $a{1}.

That's the salient point - it's an alias to the value in $a{1}, rather
than a copy, since values %hash returns aliasses, sort just shuffles
those aliasses, and foreach gives you an alias, too. So whatever you
do to $b happens to $a{1} as well.

Cheers,
Philip
-- 
Philip Newton philip.new...@gmail.com


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Randal L. Schwartz
 Dermot == Dermot  paik...@googlemail.com writes:

Dermot My first impression was that it would be 4. However, without running
Dermot it, I would say 0 on the basis that $b is scoped within the loop and
Dermot (not sure about this point) is a copy of the value in $a{1}.

That's the nice thing about foreach.  The loop variable is aliasing,
not copying, so if there are lvalues in the list, they retain their
lvalue-ness:

 $_ *= 3 for @somelist;

multiplies each element by 3, for example.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Dave Cross

On 12/01/2009 04:52 PM, Dermot wrote:

2009/12/1 Matt Sergeantmserge...@messagelabs.com:

On Tue, 1 Dec 2009 11:23:09 -0500, Matt Sergeant wrote:

On Mon, 30 Nov 2009 18:24:12 +, Chris Jack wrote:

1) Without running it to check, what does the following program output?


my %a = (3,2,1,0);


for my $b (sort values %a) {
 $b += 4;
}


print $a{1} . \n;


Bizarrely enough, on both my Snow Leopard machines (default perl
install) this outputs: 4D


This is one of those situation where I should keep quiet to avoid
showing my ignorance but I can't help myself.

My first impression was that it would be 4. However, without running
it, I would say 0 on the basis that $b is scoped within the loop and
(not sure about this point) is a copy of the value in $a{1}.


Ah, but $b isn't a copy (of the value in) $a{1}, it's actually an 
_alias_ to the value in $a{1}. Updating $b will change the value in the 
underlying hash.


Same thing applies in a foreach loop (and probably other places).

foreach my $foo (@bar) {
  # Updating $foo changes the value in @bar
}


I await the flak.


No flak. It's a common enough misunderstanding. Happy to have the chance 
to explain.


Dave...


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Dermot
2009/12/1 Philip Newton philip.new...@gmail.com:
 On Tue, Dec 1, 2009 at 17:52, Dermot paik...@googlemail.com wrote:
 (not sure about this point) is a copy of the value in $a{1}.

 That's the salient point - it's an alias to the value in $a{1}, rather
 than a copy, since values %hash returns aliasses, sort just shuffles
 those aliasses, and foreach gives you an alias, too. So whatever you
 do to $b happens to $a{1} as well.

I kinda knew I was wrong thanx to Matt post. I'm sure aliasing was
mentioned in the Perl intermediate day I went to last week. Sorry Dave
didn't absorb that point.  The good think about getting in so publicly
wrong is that I won't forget in a hurry. :)
Dp.


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Randal L. Schwartz
 Matt == Matt Sergeant mserge...@messagelabs.com writes:

Matt Yes. Though oddly enough it doesn't show up in the same terminal when 
Matt ssh'd into a Linux box. I'd like to know the reason why that is.

Maybe linux doesn't echo the ^D as uparrow D?
Or maybe linux adds a newline after it?

Dunno.  Not a Linux user.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


Re: Perl Christmas Quiz 2009

2009-12-01 Thread Matt Sergeant
On Tue, 01 Dec 2009 08:47:55 -0800, Randal L. Schwartz wrote:
 Lemme guess.  You did this:
 
 $ perl
 ... type program in here ...
 ^D (control D)
 
 The D is from your control D.
 
 Common misconception.

Yes. Though oddly enough it doesn't show up in the same terminal when 
ssh'd into a Linux box. I'd like to know the reason why that is.

Matt.

__
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
__


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Simon Wistow
On Mon, Nov 30, 2009 at 06:24:12PM +, Chris Jack said:
 6) What is the name of the official Soft Toy Camel of the London Perl Mongers?
 Bonus mark if you own one.

I bet only 2 people get this correct although I suspect several people 
will get the answer the OP was thinking of.



Re: Perl Christmas Quiz 2009

2009-11-30 Thread Dave Cross

On 30/11/09 18:24, Chris Jack wrote:


In-Reply-To: mailman.10014.1258641251.36522.london...@london.pm.org
References: mailman.10014.1258641251.36522.london...@london.pm.org


Grrr




1) Without running it to check, what does the following program output?


my %a = (3,2,1,0);


for my $b (sort values %a) {
 $b += 4;
}


print $a{1} . \n;


Without running it, I'd say 4. Having now run it, I'm glad that's what I 
said :)



2) If you received a perl mongers award for contributions to the Perl
community, what colour/type of camel would the award be?


There are quite a few people on this list who have insider knowledge here.


3) What is Perl XS? What does XS stand for?


It doesn't _stand_ for anything. It's short for XSUB which, in turn, is 
short for (I'm guessing) eXternal SUBroutine.



4) Based on your answer to the previous question, what do you conclude about
Perl programmers spelling ability?


I think this leads to theories about perl programmers' spelling 
abilities, rather than Perl programmers' spelling abilities. There's 
an important difference.



5) Write a short perl program that has a memory leak. Bonus mark for one line
solutions. Second bonus mark for the shortest program.


Sorry but it's a matter of professional pride that I _never_ write code 
with memory leaks - honest!



6) What is the name of the official Soft Toy Camel of the London Perl Mongers?
Bonus mark if you own one.


According to the Beanie Baby people, he's called Niles. According to us 
(and the 2001 leadership election ballot papers) she's called Amelia.



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.
You are allowed to use the following functions/operators x, -, length,
print plus any of the usual regular expression bestiary.

Hint: Consider converting the number to unary.


I'll leave that to the golfing experts.


8) According to amazon.co.uk, what is the best selling Perl book so far in 2009?


Does Amazon give an annual sales chart? I thought they just showed a 
current sales chart.


Current top of that chart is the Perl Template Toolkit book (or, rather, 
it will be once you've all bought copies as christmas presents for all 
your friends and family).



9) What is the youtube.com link for the perl v other languages videos
discussed on this list, and also the bubble sort video?


I must have missed those discussions.


10) What is the highest value of X that is a currently available, stable
production release of perl 5.X?


10.1


11) Think of a witty and/or interesting Perl Christmas quiz question and
answer it.


What was the most embarrassing Perl web site launch of 2009? blogs.perl.org!

Cheers,

Dave...


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Simon Wistow
On Mon, Nov 30, 2009 at 07:38:31PM +, Dave Cross said:
 According to the Beanie Baby people, he's called Niles. According to us 
 (and the 2001 leadership election ballot papers) she's called Amelia.




















[ SPOILER SPACE ]



























Actually - there are two stuffed camels. Amelia belonged to Leon (as 
much as you own a camel for they are like Patek Phillipe watches, you 
merely look after it until the next generation. Or until you stuff it 
with a sheep stuffed with chickens stuff with fish stuffed with eggs) 
and ran for election.

Niles was passed down amongst leaders - I know that Mark passed it to me 
and I passed it to Greg. Unless Greg behaved in an untoward manner 
towards the poor beast (and lets face it he has, as they say in the 
world of Policing, previous form) he should have passed him to Leon. 



Re: Perl Christmas Quiz 2009

2009-11-30 Thread Randal L. Schwartz
 Dave == Dave Cross d...@dave.org.uk writes:

 1) Without running it to check, what does the following program output?
 
 
 my %a = (3,2,1,0);
 
 
 for my $b (sort values %a) {
 $b += 4;
 }
 
 
 print $a{1} . \n;

Dave Without running it, I'd say 4. Having now run it, I'm glad that's what I 
said
Dave :)

When did sort start returning lvalues?  I bet if you did this
on an older Perl, it'd return 0.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Paul Johnson
On Mon, Nov 30, 2009 at 12:14:21PM -0800, Randal L. Schwartz wrote:
  Dave == Dave Cross d...@dave.org.uk writes:
 
  1) Without running it to check, what does the following program output?
  
  
  my %a = (3,2,1,0);
  
  
  for my $b (sort values %a) {
  $b += 4;
  }
  
  
  print $a{1} . \n;
 
 Dave Without running it, I'd say 4. Having now run it, I'm glad that's what 
 I said
 Dave :)
 
 When did sort start returning lvalues?  I bet if you did this
 on an older Perl, it'd return 0.

But you couldn't use too old a perl or it would get upset by the for
my.  So probably 5.4.x or so would be the ticket.

-- 
Paul Johnson - p...@pjcj.net
http://www.pjcj.net


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Abigail
On Mon, Nov 30, 2009 at 06:24:12PM +, Chris Jack wrote:
 
 Seeing as last year's quiz was mildly popular, I thought I'd do another
 one. I've changed the mix of questions based on what people submitted
 answers to last year - it also arguably a little more educational this
 time around.
 
 Any feedback about the quiz, either private or public is
 welcome. Apologies if any of it doesn't come out well formatted - it
 all looked fine before I hit send.
 
 
 
 5) Write a short perl program that has a memory leak. Bonus mark for one line
 solutions. Second bonus mark for the shortest program.

valgrind claims the shortest possible perl program leaks 5 bytes:

   $ valgrind perl -e''
   []
   ==19803== LEAK SUMMARY:
   ==19803==definitely lost: 5 bytes in 1 blocks.
   ==19803==  possibly lost: 0 bytes in 0 blocks.
   ==19803==still reachable: 82919 bytes in 623 blocks.
   ==19803== suppressed: 0 bytes in 0 blocks.



 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.

 You are allowed to use the following functions/operators x, -, length,
 print plus any of the usual regular expression bestiary.
 
 
 Hint: Consider converting the number to unary.

Perhaps you want a regular expression that determines whether a number
a prime. I think that's either trivial, or impossible, depending on
the restriction. If we may use (?{ })/(??{ }), it's trivial, because 
that means we can do any you can do in ordinary Perl.

With being allowed to execute Perl code, I do not think it to be possible -
I've been trying to achieve that on and off for years. Even if with (named)
rules, I believe it to be impossible. AFAIK, the set of all strings of a
unary alphabet whose length is a square cannot be recognized by a PDA - and
I don't think backreferences are powerful enough to bridge this gap.

Of course, one could cheat and write a regular expression that just lists
all the square numbers 1 .. MAX_INT. But I don't think that's the solution
you're after. 

 10) What is the highest value of X that is a currently available, stable
 production release of perl 5.X?

According to perlhist, that would be X = 001m: 5.001m is the most recent
perl it claims to be 'stable' or 'very stable'.



Abigail


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Graham Barr

On Nov 30, 2009, at 3:17 PM, Graham Barr wrote:

 
 On Nov 30, 2009, at 2:14 PM, Randal L. Schwartz wrote:
 
 Dave == Dave Cross d...@dave.org.uk writes:
 
 1) Without running it to check, what does the following program output?
 
 
 my %a = (3,2,1,0);
 
 
 for my $b (sort values %a) {
 $b += 4;
 }
 
 
 print $a{1} . \n;
 
 Dave Without running it, I'd say 4. Having now run it, I'm glad that's what 
 I said
 Dave :)
 
 When did sort start returning lvalues?  I bet if you did this
 on an older Perl, it'd return 0.
 
 sort just shuffles whatever SV* are on the stack, and values returns aliases, 
 so
 in this case you end up with aliases being returned by sort.

I meant to add that this change to sort was added to 5.6.0. So to answer your 
question it was nearly a decade ago :-)

Graham.




Re: Perl Christmas Quiz 2009

2009-11-30 Thread Graham Barr

On Nov 30, 2009, at 2:14 PM, Randal L. Schwartz wrote:

 Dave == Dave Cross d...@dave.org.uk writes:
 
 1) Without running it to check, what does the following program output?
 
 
 my %a = (3,2,1,0);
 
 
 for my $b (sort values %a) {
 $b += 4;
 }
 
 
 print $a{1} . \n;
 
 Dave Without running it, I'd say 4. Having now run it, I'm glad that's what 
 I said
 Dave :)
 
 When did sort start returning lvalues?  I bet if you did this
 on an older Perl, it'd return 0.

sort just shuffles whatever SV* are on the stack, and values returns aliases, so
in this case you end up with aliases being returned by sort.

Graham.




Re: Perl Christmas Quiz 2009

2009-11-30 Thread Abigail
On Mon, Nov 30, 2009 at 03:22:04PM -0600, Graham Barr wrote:
 
 On Nov 30, 2009, at 3:17 PM, Graham Barr wrote:
 
  
  On Nov 30, 2009, at 2:14 PM, Randal L. Schwartz wrote:
  
  Dave == Dave Cross d...@dave.org.uk writes:
  
  1) Without running it to check, what does the following program output?
  
  
  my %a = (3,2,1,0);
  
  
  for my $b (sort values %a) {
  $b += 4;
  }
  
  
  print $a{1} . \n;
  
  Dave Without running it, I'd say 4. Having now run it, I'm glad that's 
  what I said
  Dave :)
  
  When did sort start returning lvalues?  I bet if you did this
  on an older Perl, it'd return 0.
  
  sort just shuffles whatever SV* are on the stack, and values returns 
  aliases, so
  in this case you end up with aliases being returned by sort.
 
 I meant to add that this change to sort was added to 5.6.0. So to answer your 
 question it was nearly a decade ago :-)


Which was the same release where values() returned aliases instead of copies.


Abigail


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Martin A. Brooks

Merry Ex-Mass.



A sysadmin and pedant's point of view


On 30/11/2009 18:24, Chris Jack wrote:

1) Without running it to check, what does the following program output?


Something like:

bash: syntax error near unexpected token '('

Don't assume my default interpreter is your default interpreter.



2) If you received a perl mongers award for contributions to the Perl
community, what colour/type of camel would the award be?


One that knew where to use an apostrophe.



3) What is Perl XS? What does XS stand for?



Assuming infinite CPU power, infinite memory, infinite disk space and 
infinite bandwidth, writing a shopping cart...




4) Based on your answer to the previous question, what do you conclude about
Perl programmers spelling ability?



There's not enough oleum in the world.



5) Write a short perl program that has a memory leak. Bonus mark for one line
solutions. Second bonus mark for the shortest program.


See infinite memory above.



6) What is the name of the official Soft Toy Camel of the London Perl Mongers?
Bonus mark if you own one.


richardc.



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.


No. Write a program that isn't crammed with FAIL, and isn't a pain in 
the arse to roll out and maintain.  Go on, we sysadmins dare you.




8) According to amazon.co.uk, what is the best selling Perl book so far in 2009?


According to the ticket queue, I'd say Perl for dummies in 7 days or less.



9) What is the youtube.com link for the perl v other languages videos
discussed on this list, and also the bubble sort video?


http://www.youtube.com/watch?v=3jDfSqtG2E4


10) What is the highest value of X that is a currently available, stable
production release of perl 5.X?


5.10.0-19lenny2  duh.




11) Think of a witty and/or interesting Perl Christmas quiz question and
answer it.



...and here are 10 reasons why I can justify my salary




Re: Perl Christmas Quiz 2009

2009-11-30 Thread Randal L. Schwartz
 Graham == Graham Barr gb...@pobox.com writes:

Graham I meant to add that this change to sort was added to 5.6.0. So to
Graham answer your question it was nearly a decade ago :-)

Yeah, well it wasn't true when I was running Perl 2.0 on the One True
Unix under the Real Bourne Shell

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Dave Hodgkinson

On 30 Nov 2009, at 18:24, Chris Jack wrote:

 
 Seeing as last year's quiz was mildly popular, 

Bonus question:

How many people will be mildly irritated by starting a new thread
with a Reply-to: to an existing one?


-- 
Dave HodgkinsonMSN: daveh...@hotmail.com
Site: http://www.davehodgkinson.com  UK: +44 7768 490620
Blog: http://www.davehodgkinson.com/blog
Photos: http://www.flickr.com/photos/davehodg










Re: Perl Christmas Quiz 2009

2009-11-30 Thread Avleen Vig

On Nov 30, 2009, at 14:43, Dave Hodgkinson daveh...@gmail.com wrote:



On 30 Nov 2009, at 18:24, Chris Jack wrote:



Seeing as last year's quiz was mildly popular,


Bonus question:

How many people will be mildly irritated by starting a new thread
with a Reply-to: to an existing one?


Answer: none. We stopped being petty in 1997 and grew up :p


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Roger Burton West
On Mon, Nov 30, 2009 at 10:43:19PM +, Dave Hodgkinson wrote:

How many people will be mildly irritated by starting a new thread
with a Reply-to: to an existing one?

Meh, judging by the headers he's probably never used a threaded email
client so has no reason to know any better. No point in mocking the
afflicted. Just hit #...

Roger


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Ask Bjørn Hansen

On Nov 30, 2009, at 13:21, Martin A. Brooks wrote:

 A sysadmin and pedant's point of view

I take it sysadmins are too angry and bitter to understand or care for the 
holiday[1] spirit I'm sure the quiz was sent in.  Why don't you go change 
someones password?


  - ask

[1] http://xrl.us/holidays


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Graham Barr

On Nov 30, 2009, at 3:51 PM, Abigail wrote:
 
 
 I meant to add that this change to sort was added to 5.6.0. So to answer 
 your question it was nearly a decade ago :-)
 
 
 Which was the same release where values() returned aliases instead of copies.

Ah, you are right. sort was before that. the oldest perl I have is 5.4.5 which 
gives

$ /apps/perl-5.4.5/bin/perl5.00405  -l
my @a = (4,3,2,1);
for my $x (sort @a) { print ++$x; }  
print @a;
__END__
2
3
4
5
5432

Graham.




Re: Perl Christmas Quiz 2009

2009-11-30 Thread Chris Jack


Abigail abig...@abigail.be wrote
 
 On Mon, Nov 30, 2009 at 06:24:12PM +, 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.


Pedant. Perl regular expressions allow execution of arbitrary code blocks - 
which is why I put restrictions on which ordinary functions you were allowed 
to use. The actual square root algorithm, however, should only use the normal 
regular expression bestiary.

 

I was going to point you towards my talk on Perl one-liners - which shows the 
basic idea behind prime number checking and solving linear equations - but I 
can't find any of the talks on the London Perl Mongers website... The principal 
behind doing square root is similar but different.

 

As far as I'm aware, no-one has published this previously - so you can claim 
bragging rights if you do it before I give my solution.
  
_
Use Hotmail to send and receive mail from your different email accounts
http://clk.atdmt.com/UKM/go/186394592/direct/01/

Re: Perl Christmas Quiz 2009

2009-11-30 Thread James Coupe
Chris Jack chris_j...@msn.com wrote:
Abigail abig...@abigail.be wrote

 On Mon, Nov 30, 2009 at 06:24:12PM +, 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.

Pedant. Perl regular expressions allow execution of arbitrary code
blocks - which is why I put restrictions on which ordinary functions
you were allowed to use. The actual square root algorithm, however,
should only use the normal regular expression bestiary.

It's not obvious to me what you're regarding as ordinary and normal, but
I get something like...

$ perl -e '(1 x $ARGV[0]) =~ m/^(1*)((??{$1x(length($1)-1)})$)(?(2)(?{print 
length $1}))/' 4
2

I don't recommend trying it on large numbers.  1024 was about as high as
my boredom threshold could tolerate on this box.

-- 
James Coupe


Re: Perl Christmas Quiz 2009

2009-11-30 Thread James Coupe
James Coupe ja...@zephyr.org.uk wrote:
$ perl -e '(1 x $ARGV[0]) =~ m/^(1*)((??{$1x(length($1)-1)})$)(?(2)(?{print 
length $1}))/' 4
2

I don't recommend trying it on large numbers.  1024 was about as high as
my boredom threshold could tolerate on this box.

Oh, it gets better if I do something _sensible_ and make the (1*)
non-greedy - so (1*?).  Duh.

-- 
James Coupe


Re: Perl Christmas Quiz 2009

2009-11-30 Thread Ruud H.G. van Tol

Abigail wrote:

On Mon, Nov 30, 2009 at 06:24:12PM +, 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 rootif/^\d+$/'

(this is not an answer)

--
Ruud