Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I've read the following and I think I understand it -
http://www.stonehenge.com/merlyn/LinuxMag/col39.html
What I want to do is run a perl process instead of routetrace, and print a progress report to the screen as my perl program executes.
First of all, how do I call my perl program? and secondly am I right in saying that when my program has finally finished, that the while loop will exit -
while (<F>) { $buf .= $_; $cache->set($session, [0, $buf]); }

because my program will close STDIN?
Should I just replace "exec routetrace" with exec perl mylongperlprogram.pl
Thanks for your help.
Jason.

Replies are listed 'Best First'.
Re: Running a long perl process
by Zaxo (Archbishop) on Aug 23, 2004 at 21:12 UTC

    Yes, that should work fine. I'd call exec with list arguments. The form of your question has syntax errors which should cause it to fail. Here's one way, exec '/path/to/perl', '-T', '/path/to/mylongperlprogram.pl' or die $!;

    After Compline,
    Zaxo

      Thanks for your help, one more problem, how do I pass parameters to mylongperlprogram.pl?
      I tried -
      exec '/path/to/perl', '-T', '/path/to/mylongperlprogram.pl', 'number=10' or die $!;
      but number=10 is not passed.
      when I type -
      perl -T mylongperlprogram.pl number=10
      on the command line it does work.
      Whats my problem?

        You are correct in the idea of passing parameters to the script via exec's argument list. Without knowing how your script handles arguments I can't say what's going wrong.

        You might try inserting some throwaway print or warn statements to see what the script thinks is happening. Look for the values in @ARGV.

        Do you still have the problem is you make your script executable and call it directly, instead of as an explicit call to perl?

        After Compline,
        Zaxo