in reply to polymorphic perl
Then put the following into tryme.pl: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;
Now use:#!/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 it doesn't have to open the source code file. I hope you're entertained!perl -d:Dumpcode tryme.pl
The nice thing about this is that although it is a genuinely useful and effective technique, it's also extremely bizarre.
|
|---|