in reply to (TIMTOWTDI / Golf / Obfu) Airplanes in class

Oh, and I nearly forgot the ob. version using an XML-based language, interpreted of course using XML::Twig:

#!/usr/bin/perl -w use strict; use XML::Twig; eval script2perl( XML::Twig->new->parse( \*DATA)); sub script2perl { my $t= shift; foreach my $for ($t->findnodes( '//for')) { if( my $range= $for->att( 'range')) { $for->prefix( "for ($range) {\n") ->suffix( "\n}\n") ->erase; } } foreach my $print ($t->findnodes( '//print')) { $print->prefix( q{ print "}) ->suffix( q{";}) ->erase; } return $t->root->text } __DATA__ <script> <for range="1..500"> <print>I will not throw paper airplanes in class.\n</print> </for> </script>

Replies are listed 'Best First'.
Re: Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by Juerd (Abbot) on Oct 03, 2003 at 17:01 UTC

    Un-obfuscated version ;-)

    #!/usr/bin/perl -w use strict; use XML::Twig; sub script2perl { my ($t) = @_; for ($t->findnodes('//for')) { my $range = $_->att('range') or next; $_->prefix("for ($range) {\n"); $_->suffix("\n}\n"); $_->erase; } for ($t->findnodes('//print')) { $_->prefix(' print "'); $_->suffix('";'); $_->erase; } return $t->root->text; } eval script2perl XML::Twig->new->parse(\*DATA);

    I found your code hard to read. Not only the way you put curlies, but also that whitespace in your parens and around your =s is unbalanced. Is this your usual style or was it really a try to obfuscate?

    Please note: I'm not attacking, just very curious.

    Update: reading XML::Twig's documentation and source already gave me the answer: this is indeed your usual style. Wow.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }