Running a Perl script from another Perl script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob MacBob

    Running a Perl script from another Perl script

    Hi all,

    I have two scripts:

    1/ parser.pl which parses a text file and stuffs the relevant data into a
    mySQL DB - works fine no probs there

    2/ importer.pl which I want to run through all the relevant files in a
    directory and run them through parser.pl

    I've got importer.pl to the stage where it can run through a directory and
    select the correct files to be processed, but I'm not sure how to pass each
    file over to parser.pl. I also need it to wait until parser.pl has finished
    processing a file before it passes it another file to process.

    I've read the fantastic Perl Cookbook but sadly it's leaving me more
    confused than enlightened on this particular issue. :(

    Cheers,

    Bob

    --




  • Joe Smith

    #2
    Re: Running a Perl script from another Perl script

    Bob MacBob wrote:[color=blue]
    > select the correct files to be processed, but I'm not sure how to pass each
    > file over to parser.pl. I also need it to wait until parser.pl has finished
    > processing a file before it passes it another file to process.[/color]

    1) Post to comp.lang.perl. misc instead of this group (comp.lang.perl ).

    2a) Use system() for one file at a time.

    system './parser.pl',$_ foreach @files;

    2b) Use system() for all files at once (assuming that parser.pl is
    written to handle multiple arguments in @ARGV).

    system './parser.pl,@file s;


    -Joe

    Comment

    • Jim Gibson

      #3
      Re: Running a Perl script from another Perl script

      In article <mJOdnXeEo7-uNnLfRVnyvw@ecl ipse.net.uk>, Bob MacBob
      <b_macbob@hotma il.com> wrote:
      [color=blue]
      > Hi all,
      >
      > I have two scripts:
      >
      > 1/ parser.pl which parses a text file and stuffs the relevant data into a
      > mySQL DB - works fine no probs there
      >
      > 2/ importer.pl which I want to run through all the relevant files in a
      > directory and run them through parser.pl
      >
      > I've got importer.pl to the stage where it can run through a directory and
      > select the correct files to be processed, but I'm not sure how to pass each
      > file over to parser.pl. I also need it to wait until parser.pl has finished
      > processing a file before it passes it another file to process.
      >
      > I've read the fantastic Perl Cookbook but sadly it's leaving me more
      > confused than enlightened on this particular issue. :([/color]

      You should rewrite parser.pl so that it implements a subroutine (better
      still a subroutine inside a package) and pass the name of the file to
      be processed as an argument to the subroutine, rather than a
      command-line argument, which is what you might be doing now. Make sure
      there are no global variables shared between parser.pl and importer.pl.
      Then, it should be easy to execute 'do "parser.pl" ' in importer.pl,
      which will make the subroutine(s) in parser.pl available to the
      statements in importer.pl.

      If you can't get that to work, post some sample programs (not the real
      ones, unless they are very short), but post them to comp.lang.perl. misc
      (being sure to follow the guidelines for that newsgroup), because this
      newsgroup is defunct.

      Thanks.

      ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
      http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
      ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

      Comment

      • Bob MacBob

        #4
        Re: Running a Perl script from another Perl script

        Thanks to both Joe and Jim.

        I'll give those solutions a go and if I have any more questions, I'll post
        on the misc group.

        Cheers,

        Bob


        Comment

        • Bob MacBob

          #5
          Re: Running a Perl script from another Perl script

          Thanks to both Joe and Jim.

          I'll give those solutions a go and if I have any more questions, I'll post
          on the misc group.

          Cheers,

          Bob



          Comment

          • Bob MacBob

            #6
            Re: Running a Perl script from another Perl script

            Thanks to both Joe and Jim.

            I'll give those solutions a go and if I have any more questions, I'll post
            on the misc group.

            Cheers,

            Bob



            Comment

            Working...