Use single perl instance multiple times

Discussion in 'Perl Misc' started by mseele, Aug 1, 2008.

  1. mseele

    mseele Guest

    Hi,

    i have to "parse/compile" lot's of perl files (as fast as possible)
    and work with the output (...Can't locate XYZ.pm in @INC (@INC
    contains: XYZ) at - line 7. BEGIN failed--compilation aborted at -
    line 7....).

    For now i iterate over the files, create a new perl process for every
    file (perl -c -W -Mstrict -I XYZ) and write the bytes of the current
    file into the process.
    But it is very expensive to start a new perl process for every file to
    parse.

    Is it possible to use only one perl process for parsing multiple perl
    files?
    I mean: open only one perl process, write in the bytes of a file, read
    the output, "reset" the perl process (change @inc...), write in the
    bytes of the next file, read the output, "reset" the perl
    process...and so on till all files will be parsed/compiled. Then exit
    the perl process. Is this possible?
    What do i have to "reset/new initalize" after one file is processed?
    Only the @INC or more?
    How can i tell the perl process that one file is fully written to the
    input stream and the parser/compiler should write the output to the
    output stream?

    Thanks,
    Michael
    mseele, Aug 1, 2008
    #1
    1. Advertising

  2. mseele

    Dr.Ruud Guest

    mseele schreef:

    > Is it possible to use only one perl process for parsing multiple
    > perl files?


    Not without side effects, but maybe good enough:

    package JEQVCHSAFCUDFNDGSADKFFH;

    for $file (@files) {
    eval {
    require $file;
    1;
    }
    or do {
    my $err = $@;
    printf STDERR "%s\n", $err;
    };
    }

    Next progress would be forking suicidals, I suppose.

    Alternative approaches:
    for f in *.pm ; do perl -Mstrict -wc $f ; done 2>&1 |grep -vP "\.pm
    syntax OK$" |less
    for f in *.pm ; do perl -Mstrict -wc $f 2>&1 |grep -vP "\.pm syntax
    OK$" ; done |less

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Aug 1, 2008
    #2
    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. Larry Marburger

    XSLT: Loading Single Image Multiple Times

    Larry Marburger, Jun 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    371
    Teemu Keiski
    Jun 21, 2004
  2. chris brat
    Replies:
    1
    Views:
    630
    chris brat
    May 10, 2006
  3. Todd
    Replies:
    5
    Views:
    1,011
    Roedy Green
    Aug 23, 2007
  4. Peng Yu
    Replies:
    17
    Views:
    688
    Peng Yu
    Sep 14, 2008
  5. Jack Steven
    Replies:
    2
    Views:
    430
    Chris Rebert
    Mar 9, 2009
Loading...

Share This Page