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

Hi Monks!

I am trying to set cookies by calling a Perl script from another Perl script using these line here, it is not working, does any body know how I could accomplish that using any other way?
Here is the code I am using to call my cookie script:

open(FCOOKIE, "|cookie.pl name=$name buddy=$buddy'"); # open cookie.pl + as a pipe, the variables name and buddy are now available to retriev +e in cookie.pl as parameters while(<FCOOKIE>){ print $_; # Print output to test } close(FCOOKIE);


Thanks!

Replies are listed 'Best First'.
Re: Calling a Perl script from a Perl script
by davorg (Chancellor) on Sep 15, 2006 at 15:47 UTC
    it is not working

    That's not a very detailed description of the problem. It really doesn't give us much to go on. You should explain what unexpected behaviour you see. Does nothing happen? Do you see an error message? Does your computer burst into flames?

    As has already been pointed out, it looks like you're trying to read from a filehandle that is only open for writing. If you had use warnings in your code then Perl would tell you about this problem. I don't understand why people try to write code without asking Perl for all the help it can give.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Calling a Perl script from a Perl script
by wazzuteke (Hermit) on Sep 15, 2006 at 15:39 UTC
    Sure thing. First, though, I may recommend Super Search. It does a good job in finding common questions such as this very one.

    Here is a search result I pulled with a pretty fair amount of nodes with very similar questions.

    Otherwise, take a look into the exec() and system() perl functions. They will enable Perl to call an external application while not relying on the open() function to pipe into the file you are attempting to run.

    Also, you will need to make sure the called script has execute priveldges.

    Hope that helps

    perl -le '$.=[qw(104 97 124 124 116 97)];*p=sub{[@{$_[0]},(45)x 2]};*d=sub{[(45)x 2,@{$_[0]}]};print map{chr}@{p(d($.))}'
Re: Calling a Perl script from a Perl script
by caelifer (Scribe) on Sep 15, 2006 at 15:40 UTC
    Your pipe is open for writing not reading.
       perldoc -f open
    
    will explain in greate details how to open a pipe.
Re: Calling a Perl script from a Perl script
by swampyankee (Parson) on Sep 15, 2006 at 15:48 UTC

    Could you be a bit more forthcoming with what you mean by "it's not working"?

    At first glance, the code sample you've posted here (copied here:

    open(FCOOKIE, "|cookie.pl name=$name buddy=$buddy'"); #open cookie.pl +as a pipe, the variables name and.... ^
    )has a mismatched quote (at the caret), so there's a syntax error which may cause a problem.

    Next, I you should check to see if the open failed, check to see if $name and $buddy are set, have legitimate values, and are not being munged up by the shell (I think that open uses the shell when the a command is opened). Third, check out perlipc, if you haven't already done so.

    <update> Struck out statement about syntax error; see davorg's comment.

    emc

    At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.

    —Igor Sikorsky, reported in AOPA Pilot magazine February 2003.
      At first glance, the code sample you've posted here ([removed])has a mismatched quote (at the caret), so there's a syntax error.

      There's no need to match quotes within a quoted string. Depending on what the string represents, it might (of course) be a semantic error. But it won't be a syntax error.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg