How can I see the expanded file after all the require files are loaded

R

Ray Muforosky

Hello everyone, I'm lost.

How I do see or save the content of fileA after it has loaded all the
required files.


fileA
-----
#!perl
a="help"
require file1
require file2

How do I see or save the expanded fileA?

Thanks for all your help
 
T

Tad McClellan

Ray Muforosky said:
How I do see or save the content of fileA after it has loaded all the
required files.


Why do you want to see or save the content of fileA after it has
loaded all the required files?

That is, what do you hope to gain by doing that?

fileA
-----
#!perl
a="help"
require file1
require file2


That is not Perl.

This is the Perl newsgroup.

Did you have any Perl code that you wanted to include?
 
X

xhoster

Ray Muforosky said:
Hello everyone, I'm lost.

How I do see or save the content of fileA after it has loaded all the
required files.

There is nothing to see.
fileA
-----
#!perl
a="help"
require file1
require file2

How do I see or save the expanded fileA?

There is no "expanded fileA". "require" is not a macro or preprocessor.

Xho



subspace/perl_misc> perl -MO=Deparse,-p
require Data::Table;
__END__
produces this output:

require Data::Table;
__DATA__
 
R

Ray Muforosky

Tad said:
Why do you want to see or save the content of fileA after it has
loaded all the required files?

That is, what do you hope to gain by doing that?




That is not Perl.

This is the Perl newsgroup.

Did you have any Perl code that you wanted to include?


example:
file1:
===
#!/usr/local/bin/perl
$a =12;
require file2;
$b = $z;
require file3;
$c = $y;
print $a;


file2:
====
$z = 200;
1;


file3
===
$y = "foo";
1;


So, is it possible to save file1 after requiring file2 and file3
file1 becomes:

#!/usr/local/bin/perl
$a =12;
$z = 200;
$b = $z;
$y = "foo";
$c = $y;
print $a;
 
P

Paul Lalli

Ray said:
example:
file1:
===
#!/usr/local/bin/perl
$a =12;
require file2;
$b = $z;
require file3;
$c = $y;
print $a;


file2:
====
$z = 200;
1;


file3
===
$y = "foo";
1;


So, is it possible to save file1 after requiring file2 and file3
file1 becomes:

#!/usr/local/bin/perl
$a =12;
$z = 200;
$b = $z;
$y = "foo";
$c = $y;
print $a;

What makes you think that file1 "becomes" that? file1 is not changed
by anything you've demonstrated. The code from file2 and file3 is
included in the execution of file1, but the source itself is not
changed at all.

It's time for you to tell us what you're actually *trying* to do,
rather than simply telling us what you've already decided is the way to
go about doing that. I cannot think of any reason you would want to do
what you claim you want to do.

Paul Lalli
 
T

Tad McClellan

Ray Muforosky said:
require file2;


You need quotes around the argument to require.

So, is it possible to save file1 after requiring file2 and file3
file1 becomes:


Why do you want to save file1 after requiring file2 and file3?

That is, what do you hope to gain by doing that?

#!/usr/local/bin/perl
$a =12;
$z = 200;
$b = $z;
$y = "foo";
$c = $y;
print $a;


This one-liner will make the changes to file1 that you seem to
be asking for...


perl -p -i.orig -e 's/require (\S*)\n/`head -1 $1`/e' file1


.... but I think you probably should be asking for something else.



What problem is it that you are ultimately trying to solve?
 
R

Ray Muforosky

Tad said:
You need quotes around the argument to require.




Why do you want to save file1 after requiring file2 and file3?

That is, what do you hope to gain by doing that?




This one-liner will make the changes to file1 that you seem to
be asking for...


perl -p -i.orig -e 's/require (\S*)\n/`head -1 $1`/e' file1


... but I think you probably should be asking for something else.



What problem is it that you are ultimately trying to solve?

I inherited this code that I'm currently maintaning and it has perl
files scartered all over and uses require everywhere. So, I'm trying to
get a comprehensive listing of all the source code including all the
required files.

RM
 
P

Paul Lalli

Ray said:
I inherited this code that I'm currently maintaning and it has perl
files scartered all over and uses require everywhere. So, I'm trying to
get a comprehensive listing of all the source code including all the
required files.

There simply is no such thing. The code in the require()d modules is
not added to the main source file. If you'd like, you can examine the
%INC variable to get a list of all modules that have been included,
regardless of how many levels deep. Then read the documentation for
each of those modules. If the code is at all well written, it should
not be necessary to read the code in the order that the modules are
required. If the code is not well-written enough for that to be true,
then you have my sympathies.

Paul Lalli
 
U

Uri Guttman

RM> I inherited this code that I'm currently maintaning and it has perl
RM> files scartered all over and uses require everywhere. So, I'm trying to
RM> get a comprehensive listing of all the source code including all the
RM> required files.

a classic XY problem. why didn't you state this to begin with? the
solution is much easier that you realize. the %INC hash (see perldoc
perlvar) has the path to all source files that have loaded by
require/use. just dump that before the program starts (in a INIT block
should work) and you will have all of the files used by your
program.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top