Gathering Source files

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


If I have file1 that loads (require file2 and files), is it possible
save the content of file file after the load.

$a ;
require file2;
$b = $z;
require file3;
$c = $y;
print $a;

$z = 200;

$y = "foo";

So, is it possible to save file1 after loading file2 and file3
file1 becomes:
$a ;
$z = 200;
$b = $z;
$y = "foo";
$c = $y;
print $a;


Re: Gathering Source files

Quoted text here. Click to load it

Those are not (in general) the same thing, because of the file scoping
of lexical variables and such.  I know that in the example you give there
are no lexical variables, but then again in the example you give it is
trivially easy to do what you want by hand.  So I have to assume that the
real world extends beyond your example.

A not very generic (or good) solution would be something like this:

warn "Untested";
$program1 =~ s/\brequire ([^;]+);/"\n".get_file($1)."\n"/eg;

sub get_file {
  ## see perldoc -f require for how to find file when not in cwd.
  open my $fh, "<", "$_[0].pm" or die "$_[0]: $!";
  local $/;
  return <$fh>;

Among other things that would break this would be quoted things that have
the word "require" within them, so look at Filter::Simple and such modules
to fix that.


-------------------- http://NewsReader.Com / --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB

Site Timeline