in reply to Program unsuspectingly dies with no reason why. -FIXED!

Here are the relevant lines:

&clean_the_file(); sub clean_the_file { my ( $sourcefile, $removeq ) = @_; `grep -v $removeq $sourcefile > $tempfile`; }

You're calling clean_the_file with no arguments, and passing those (no) arguments on to grep, which is going to hang waiting for input.

That's my guess.

Replies are listed 'Best First'.
Re^2: Program unsuspectingly dies with no reason why.
by misconfiguration (Sexton) on Feb 13, 2008 at 21:21 UTC
    I think I'm going to have to agree with Kyle. Does anyone think I should remove the grep -v function from backticks and have Perl handle it with the system(); call? I think I'm going to try it this way, so far not much luck with the issue. Thanks for all of the replies so far!

      Backticks are for when you want to capture the output of some shell command. In this case, you're redirecting output to a file, so backticks won't do that. Your backticks also don't give you anything in a void context.

      That said, putting the same thing in system won't help either. It's the underlying grep that's hanging.

      I think that grep needs to get some arguments. You could do this, minimally:

      `grep -v $removeq $sourcefile /dev/null /dev/null > $tempfile`;

      That won't hang, but it also won't work until $removeq and $sourcefile are right. You probably ought to be passing them in initially:

      &clean_the_file( $sourcefile, $removeq );

      I can't tell what $sourcefile should be, though.

      Hope this helps.

        Well so far, even after passing those elements to the subprocess call "&clean_the_file();" I still had no luck. Albeit, I did remember reading about subprocess' being named with funky underscores causing issues with Perl awhile back. This may not be the case, but I removed the name of the sub() function renamed it to cleanthefile();.

        I commented everything out and just printed my variables $sourcefile and $removeq, $sourcefile prints the directory name as expected, BUT - $removeq spits this output out
        [root@oailxpp02 ccsys]# /root/mkpq -r queue-04 Global symbol "$removeq" requires explicit package name at /root/mkpq +line 87. Execution of /root/mkpq aborted due to compilation errors.

        My guess is: the scalar isn't being handled properly, the subprocess can't bring it into it's set of instructions, am I on the right track? Does anyone have any recommendations?
      I think you missed Kyle's point. Using system instead of backticks to call grep should not matter here.

      To illustrate Kyle's point, add these lines just before your grep line:

      print "removeq = $removeq\n"; print "sourcefile = $sourcefile\n";

      I suspect these variables will not contain what you expect them to.