http://qs1969.pair.com?node_id=550635

This probably doesn't belong anywhere, but Meditations is as good a place as any I suppose I was crawling through someone else's code today. I was supposed to go port it to use some new infrastructure of ours, but after I clawed my eyes out, we decided I should rewrite it. The clincher for me was:
for ( @data ) { sysopen ($fh, "$log", O_WRONLY|O_APPEND); $fh->print ("$_"); close $fh; }
This sent me off on a rant. This sent my manager and I off into a tailspin inventing god-awful code. My final contribution is nothing short of contrived ugliness, and I wanted to share it with you, my esteemed fellow monks:
#!/usr/bin/perl my $filename = $ARGV[0]; my @size = grep /./, map { $_ } split //, `wc -l $filename`; my $i = ''; my $loop = 1; while ( $loop ) { my $d = shift @size; if ( $d =~ /\d/ ) { $i .= $d; } else { $loop = 0; } } for ( 1 .. $i ) { my $line = `head -$_ $filename | tail -1`; print $line; }
Since I'm dealing with the ugliness someone else unleashed on the world, somehow I feel better having unleashed that on the world, and it's better to do it here than in real code. This isn't about obfuscation, it's about just plain god awful code that does the job (in this case a version of 'cat'). A reminder of what we strive to not unleash on people. So make me cringe...show me your ugliness.