Martin Tithonium (tithonium) wrote,
Martin Tithonium
tithonium

  • Mood:

Marty's Perl Quiz of the Day

Edit: Added a linebreak to make it a little less wide. Also: it's perl. FYI.
Edit: Here's some more information. I wrote this in a mason file. $out is the concatination of several $m->scomp() calls into subcomponents

Ok, tell me what I'm doing here:
  my $c = 0;
  $out =~ s/[\r\n][\r\n]+/\n/gs;
  $out =~ s#<hr[^>]*>#-----#gis;
  $out =~ s#</?[^t/][^>]*>##gis;
  $out =~ s#  +# #gs;
  $out =~ s#<tr[^>]*>#\n#gis;
  $out =~ s#</tr[^>]*>##gis;
  $out =~ s#&#&#gis;
  $out =~ s# # #gis;
  my $maxlen = 0;
  while($out =~ m#<td[^>]*>(.+?)</td>\s#gsi) {
    $maxlen = length($1) if length($1) > $maxlen;
  }
  $maxlen++;
  $out =~ s#<td[^>]*>(.+?)</td>\s#
            sprintf($c++ % 2 ? "%9s" : "%${maxlen}s ", $1)#gsie;
  $out =~ s#<[^>]+>##gs;
  $out =~ s/^\s*$//gm;
  $out =~ s/[\r\n][\r\n]+/\n/gs;
Closest correct answer to the full explanation wins.
I'll figure out a prize later.
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 22 comments