> Have you read the Perl Golf column in The Perl Review?
> http://www.theperlreview.com/
Just finished studying Perl Review 0,3, and the explanation of the anagram
solution.
> I'd be interested in hearing whether you found it helpful in de-mystifying
> some of the complexities of the winning solutions. If you don't find it
> helpful, I'd appreciate any feedback you may have.
Let me start of by saying that I haven't read Programming Pearls. I
currently have read Learning Perl, and some of Programming Perl. I also have
Advanced Perl, but I haven't been able the grasp much of it yet.
The solution:
Map!s/
^/ /m|//||print,sort%0for map$0{0,sort/./g}
..+$_,sort<>
Then you describe the the 'signature technique' from programming pearls.
$hash{ join '', sort split // } .= $_
Golf version: $0{0,sort/./g}.=$_
If this subpart is passed the string: perlgolf
It will first split the word into characters: p e r l g o l f
And then sort the characters: e f g l l o p r
At his point I am actually understanding the explanation.
The next part of the explanation is:
The deprecated hash key auto-join(used in Perl 4 to create multi-dimensional
data structures) joins the signature. Listing a constant scalar before the
split-sort forces it into list context, causing the auto-join.
I'm guessing this means: e f g l l o p r => efgllopr
What is the constant scalar? The 0 in {0,sort/./g}?
I thought $0{} was a hash and '0,sort/./g} was in some freaky way the key.
If I am correct in assuming that $0{} is a hash-scalar. Then it would seem
to me like:
%0 = qw(efgllopr => perlgolf);
At this point, the end of the right side(the 'signature technique'), I'm not
sure if I'm grasping it. So, I would like to write some code of my own to
understand this:
#!/usr/bin/perl
$a = "perlgolf";
$0{0,sort/./g}.=$a; ## I'm guessing $hash{'key',statements}=$value
@key = keys (%0);
print "$key[0]"; ##�expecting 'efgllopr'
[localhost:~/Programming/Perl/Various code] tor% ./TPR03
0[localhost:~/Programming/Perl/Various code] tor%
$key[0] == 0?
I'm officially lost. And, here I'm not sure if took a wrong turn somewhere
or if my 'understanding code' is correct.
While I am aware that my thoughts at least go in the right direction(you
explain this further later on), I simply can't understand it.
Why doesn't my simple test script work?
It would be nice if questions like these could be asked here. And, if you
guys don't mind, I might start asking :)
I bet I could keep you guys busy in between holes.
Just wait for my cantor questions :)
When it comes to the Perl Review explanation of the holes, I think a user of
my skill level would need some additional help/explanation. At least from
what I've seen from TPR 0,2 and 0,3.
In TPR0,3, Lars Mathiesen won with 61 strokes, I probably shouldn't even
expect to understand his solution. But, if you have the time and will to
make a similar explanation of a solution with say double the amount of
strokes. It might be easier for me* to use that as a stepping stone to grasp
the Ultimate solution(the winning solution).
I apologize if it seems that I'm demanding to much, just trying to provide
information from a beginners perspective.
*me being people on my level.
Tor