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

Discussion in 'Perl Misc' started by Ray Muforosky, May 26, 2006.

  1. 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
     
    Ray Muforosky, May 26, 2006
    #1
    1. Advertising

  2. Ray Muforosky <> wrote:

    > 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?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, May 26, 2006
    #2
    1. Advertising

  3. Ray Muforosky

    Guest

    "Ray Muforosky" <> wrote:
    > 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__

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , May 27, 2006
    #3
  4. Tad McClellan wrote:
    > Ray Muforosky <> wrote:
    >
    > > 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?
    >
    >
    > --
    > Tad McClellan SGML consulting
    > Perl programming
    > Fort Worth, Texas



    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;
     
    Ray Muforosky, Jun 1, 2006
    #4
  5. Ray Muforosky

    Paul Lalli Guest

    Ray Muforosky wrote:
    > Tad McClellan wrote:
    > > Ray Muforosky <> wrote:
    > >
    > > > 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?

    > 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
     
    Paul Lalli, Jun 1, 2006
    #5
  6. Ray Muforosky <> wrote:
    > Tad McClellan wrote:
    >> Ray Muforosky <> wrote:
    >>
    >> > 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?



    > 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?



    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Jun 3, 2006
    #6
  7. Tad McClellan wrote:
    > Ray Muforosky <> wrote:
    > > Tad McClellan wrote:
    > >> Ray Muforosky <> wrote:
    > >>
    > >> > 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?

    >
    >
    > > 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?


    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
    >
    >
    >
    > --
    > Tad McClellan SGML consulting
    > Perl programming
    > Fort Worth, Texas
     
    Ray Muforosky, Jun 5, 2006
    #7
  8. Ray Muforosky

    Paul Lalli Guest

    Ray Muforosky wrote:
    > 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
     
    Paul Lalli, Jun 5, 2006
    #8
  9. Ray Muforosky

    Uri Guttman Guest

    Re: How can I see the expanded file after all the require files areloaded

    >>>>> "RM" == Ray Muforosky <> writes:

    RM> Tad McClellan wrote:

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


    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

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Jun 5, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flip
    Replies:
    3
    Views:
    979
    Tony Morris
    Feb 9, 2004
  2. TMT32
    Replies:
    0
    Views:
    752
    TMT32
    Jul 12, 2006
  3. qwweeeit
    Replies:
    2
    Views:
    650
    qwweeeit
    Dec 14, 2005
  4. ton
    Replies:
    2
    Views:
    2,160
  5. Alex Young
    Replies:
    2
    Views:
    92
    Alex Young
    Mar 16, 2011
Loading...

Share This Page