A while ago, I was writing a large script with a lot of data in a BEGIN block. I forget why.
But it was late in the morning and, of course, some part of the script wasn't working right, so I wrote a quick debugging routine using Data::Dumper that dumped some of the values in the BEGIN block.
When I came back to it the next day, it was entirely incomprehensible, so I boiled it down to the following code:
#!/usr/bin/perl use warnings; use strict; use constant DEBUG => not undef; use Data::Dumper; BEGIN { my ($a, $b, $c) = (1, 2, 3); my $deb; if (DEBUG) { $deb = sub { print Data::Dumper->Dump([$a, $b, $c], [qw/a b c/]); }; } else { $deb = sub { warn "Debugging not enabled!\n"; } } sub debug { &$deb } }
The warn is there for when I removed the debugging information.
I would really like to know what I was thinking when I wrote this...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How not to write subroutines
by strat (Canon) on Jan 15, 2006 at 10:38 UTC | |
by nacka (Friar) on Jan 15, 2006 at 13:38 UTC | |
by gustavderdrache (Acolyte) on Jan 15, 2006 at 15:38 UTC | |
|
Re: How not to write subroutines
by brian_d_foy (Abbot) on Jan 15, 2006 at 17:18 UTC | |
by gustavderdrache (Acolyte) on Jan 15, 2006 at 19:38 UTC | |
|
Re: How not to write subroutines
by CountOrlok (Friar) on Jan 15, 2006 at 07:48 UTC | |
by gustavderdrache (Acolyte) on Jan 15, 2006 at 15:24 UTC | |
|
Re: How not to write subroutines
by holli (Abbot) on Jan 15, 2006 at 15:53 UTC | |
by gustavderdrache (Acolyte) on Jan 15, 2006 at 16:08 UTC |