This is part a usenet article I posted a while back in
response to someone who was doing something similar.
I hope it is helpful and interesting.
But finally, you might find a different approach amusing. You need
the following utility module. Put the this code into the file
Devel/Dumpcode.pm:
package Devel::Dumpcode;
sub DB::DB { } # Do nothing special
sub main::source_of_function {
my $package = caller;
$function = $package . '::' . shift();
my ($file, $start, $end) =
$DB::sub{$function} =~ /(.*):(\d+)-(\d+)/;
@{"::_<$file"}[$start..$end];
}
1;
Then put the following into
tryme.pl:
#!/usr/bin/perl
for (;;) {
print "Gen = ", Gen_val(), "\n";
my @code = source_of_function('Gen_val');
for (@code) {
last if s{(\d+)(?=;\s+\# EDIT ME)}
{(($1 * 1103515245 + 12345) / 65536) % 32768}e;
}
eval join '', @code;
}
sub Gen_val {
1; # EDIT ME
}
Now use:
perl -d:Dumpcode tryme.pl
Now it doesn't have to open the source code file. I hope you're entertained!
The nice thing about this is that although it is a genuinely useful
and effective technique, it's also extremely bizarre.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.