[19749] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1944 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 17 09:05:39 2001

Date: Wed, 17 Oct 2001 06:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003323911-v10-i1944@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 17 Oct 2001     Volume: 10 Number: 1944

Today's topics:
    Re: A bug in s///e? <bart.lateur@skynet.be>
    Re: Can't get the output for shell command from CGI (Carfield Yim)
    Re: Can't get the output for shell command from CGI <kaysb@uten.net>
    Re: Can't get the output for shell command from CGI (Rod)
    Re: Can't get the output for shell command from CGI (Garry Williams)
        Deadlock with perl using ssh/sqlplus in forked processe (Thomas.auer)
    Re: Entering Name-Value pairs - Still Confused <s_grazzini@hotmail.com>
    Re: Entering Name-Value pairs - Still Confused <wsegrave@mindspring.com>
        GET and POST problem </Marek/>" <mapow@hi.hinet.hr>
    Re: GET and POST problem <joe+usenet@sunstarsys.com>
    Re: GET and POST problem (Martien Verbruggen)
    Re: GET and POST problem (Chas Friedman)
    Re: HELP - QUICK Question!!! <tintin@snowy.calculus>
    Re: HOW TO enter name value pairs manually? - STILL CON <uri@sysarch.com>
    Re: HOW TO enter name value pairs manually? - STILL CON <pne-news-20011017@newton.digitalspace.net>
    Re: How to restore a filehandle tie correctly? <newspost@coppit.org>
        How to run exec() or system() in a PERL CGI script ? (Bosco)
    Re: How to run exec() or system() in a PERL CGI script  <Thomas@Baetzler.de>
        How to test the presence of quotes in arguments ? (Laird)
    Re: How to test the presence of quotes in arguments ? (Anno Siegel)
    Re: How to test the presence of quotes in arguments ? <bernard.el-hagin@lido-tech.net>
    Re: How to test the presence of quotes in arguments ? <jurgenex@hotmail.com>
    Re: how to write to different host+port on one socket? <Thomas@Baetzler.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 17 Oct 2001 09:36:40 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: A bug in s///e?
Message-Id: <6sjqst4qp8igofr1mpkeuqpge51in8quuq@4ax.com>

Joe Schaefer wrote:

>Right- I think what happens is that the replacement text is treated
>as a block of code- the last line of which is evaluted in scalar 
>context and used as the replacement text.  Fatal errors in this
>code block are *not* trapped, so eval is really not relevant here.
>
>But a second "e" *will* eval the result as an EXPR.

>I always used the mnemonic that the first "e" was for "executing" (but 
>not exec()ing) the code, while the second was for "eval"ing the result.  
>I don't know where I picked this up, but it stuck.

Yeah, I agree with you there. The strange thing is that, even though
I've been familar with this behaviour for years -- and it's the proper
thing to do most of the time -- now that I want to do something else, I
was baffled that it didn't work. "DWIM" depends on what you want to do.

If you want to see something quite awkward, compare these -- it seems to
be doing even less with the /e than without, but that's only on the
surface:

	$orig = "X foo Y\n";
	my $repl = 'not important';
	$_ = $orig; s/foo/'$repl'/; print;
	$_ = $orig; s/foo/'$repl'/e; print;
->
	X 'not important' Y
	X $repl Y

-- 
	Bart.


------------------------------

Date: 16 Oct 2001 23:13:06 -0700
From: carfield@programmer.net (Carfield Yim)
Subject: Re: Can't get the output for shell command from CGI
Message-Id: <c40dea5f.0110162213.50ad5fc7@posting.google.com>

Ron Reidy <ron@indra.com> wrote in message news:<3BCC7179.7DE9358F@indra.com>...
> Carfield Yim wrote:
> > 
> > I want to display a HTML of java code to my visitor, so I write the
> > following script to serve this:
> > 
> > #!/usr/bin/perl -w
> > use CGI qw(param);
> > 
> > print "Content-type: text/html";
> > 
> > $command = "/usr/local/bin/java2html <
> > /server/http/java_store/applet/chat/src/com/lyrisoft/auth/mysql/Mysql.java
> > --title \"powered by java2html from gun.org\"|";
> > open(IN, $command) || die "cannot open file for reading: $!";
> > 
> > while (<IN>) {  # read a line from the command into $_
> >     print $_;   # print that line to file $b
> > }
> > close(IN) || die "can't close file: $!";
> > 
> > The $command can successful run at shell and display the HTML to
> > stdout, however in this CGI I get the following error:
> > 
> > /usr/local/bin/java2html: unrecognized option
> > `--code=http://www.carfield.com.hk/java_store/SUN_j2se_runtime_lib_src_1.4/java/lang/String.java'
> > can't close file:  at /var/www/cgi-bin/java2html.pl line 14.
> > [Wed Oct 17 00:50:13 2001] [error] [client 10.0.0.1] Premature end of
> > script headers: /var/www/cgi-bin/java2html.pl
> > 
> > why will this happen?
> You open() command is suspicious.  If you want the output, you need to
> open like this: open(IN, "|$command") || die ...
> 
> See perldoc perolfunc and look for open() and perldoc perlipc


The most strange thing is that why the script will show my domain as
parameter of java2html. I haven't passed it to my program.

I find that even I correct the open() function call and my script can
run normally at shell, I still can't run it as CGI, why?


------------------------------

Date: Wed, 17 Oct 2001 08:40:23 -0700
From: "Kay Bærulfsen" <kaysb@uten.net>
Subject: Re: Can't get the output for shell command from CGI
Message-Id: <iH9z7.29$yq6.1320@news3.oke.nextra.no>


"Carfield Yim" <carfield@programmer.net> wrote in message
news:c40dea5f.0110160857.6a6762d8@posting.google.com...

> why will this happen?

btw, your HTTP-header is wrong.

Try something like this;

print "Content-type: text/html\n\n";


--
Kay Bærulfsen




------------------------------

Date: 17 Oct 2001 03:10:50 -0700
From: rbaldwin@yahoo.com (Rod)
Subject: Re: Can't get the output for shell command from CGI
Message-Id: <caab58a6.0110170210.33b7e5b9@posting.google.com>

I find the easiest way to get the results of a system command is to
use the "system" command:

$command = "/usr/local/bin/java2html <
/server/http/java_store/applet/chat/src/com/lyrisoft/auth/mysql/Mysql.java
--title \"powered by java2html from gun.org\"|";
$commandResult = system($command);
print $commandResult;

Cheers.

carfield@programmer.net (Carfield Yim) wrote in message news:<c40dea5f.0110160857.6a6762d8@posting.google.com>...
> I want to display a HTML of java code to my visitor, so I write the
> following script to serve this:
> 
> #!/usr/bin/perl -w
> use CGI qw(param);
> 
> print "Content-type: text/html";
> 
> $command = "/usr/local/bin/java2html <
> /server/http/java_store/applet/chat/src/com/lyrisoft/auth/mysql/Mysql.java
> --title \"powered by java2html from gun.org\"|";
> open(IN, $command) || die "cannot open file for reading: $!";
> 
> while (<IN>) {  # read a line from the command into $_
>     print $_;   # print that line to file $b
> }
> close(IN) || die "can't close file: $!";
> 
> The $command can successful run at shell and display the HTML to
> stdout, however in this CGI I get the following error:
> 
> /usr/local/bin/java2html: unrecognized option
> `--code=http://www.carfield.com.hk/java_store/SUN_j2se_runtime_lib_src_1.4/java/lang/String.java'
> can't close file:  at /var/www/cgi-bin/java2html.pl line 14.
> [Wed Oct 17 00:50:13 2001] [error] [client 10.0.0.1] Premature end of
> script headers: /var/www/cgi-bin/java2html.pl
> 
> why will this happen?


------------------------------

Date: Wed, 17 Oct 2001 11:26:27 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Can't get the output for shell command from CGI
Message-Id: <slrn9sqqn3.kmn.garry@zfw.zvolve.net>

On 16 Oct 2001 09:57:23 -0700, Carfield Yim <carfield@programmer.net>
wrote:

> I want to display a HTML of java code to my visitor, so I write the
> following script to serve this:
> 
> #!/usr/bin/perl -w
> use CGI qw(param);
> 
> print "Content-type: text/html";


Problem one: invalid (incomplete) header.  


> $command = "/usr/local/bin/java2html <
> /server/http/java_store/applet/chat/src/com/lyrisoft/auth/mysql/Mysql.java
> --title \"powered by java2html from gun.org\"|";
> open(IN, $command) || die "cannot open file for reading: $!";


Slight irritation: the error message is misleading and ambiguous.
(Fortunately, most errors will be accurately reported by Perl anyway.)  


> while (<IN>) {  # read a line from the command into $_
>     print $_;   # print that line to file $b
> }
> close(IN) || die "can't close file: $!";


Problem two: close() returns false when the process fork()ed by the
popen() returns a non-zero status.  

See the close() section of the perlfunc manual page for the behavior
of close() on a pipe.  You need to check more than the truth of the
result of close in this case.  (There was a recent thread about this
issue here.  You might want to search for it on groups.google.com.)  

-- 
Garry Williams


------------------------------

Date: 17 Oct 2001 04:51:42 -0700
From: thomas.auer@cspb.com (Thomas.auer)
Subject: Deadlock with perl using ssh/sqlplus in forked processes
Message-Id: <b1cd4c0a.0110170351.682aecbf@posting.google.com>

Hi all,

I am experiencing problems with a perl script that I use to invoke
sqlplus and ssh. It transfers files from a remote location using ssh.
I am using perl 5.005_03 on Sun Solaris.

The program forks, and in the subprocesses created both sqlplus and
ssh are invoked. While this works fine most of the time, it
occasionally happens that either sqlplus or ssh locks. For ssh I have
found that it is hanging in a select statement.

I have reopened STDIN, STDERR and STDOUT in the new process, but it
did not help anyway.

Below are some code snippets with which I experienced the problem. In
the code below, the waitpid for the process that is deadlocked never
returns, and for ssh I have seen (using truss) that it is hanging in a
select statement. I am not sure why sqlplus is locking, but I would
assume that the error reasons are identical. I already searched old
postings, but I did not find anything which seemed relevant to my
problem.

Any feedback would be welcome.

Thanks in advance for your help,
Thomas Auer (thomas dot auer at cspb dot com)


First are the sections of my code (from a separate module) which are
responsible to start processes and to collect all children.

sub startProcess
  {
    my($procedure,$nrOfProcesses,$procName,@params) = @_;
    my($newPid,$curNr);

    # first, check whether a new process can be started
    if (($curNr = getNrOfProcesses()) >= $nrOfProcesses)
      {
        #errorWrite("No new process can be started, processing".
        #  " synchronously!\n".
        #   "  current number of processes $curNr ".
        #   "maximum number $nrOfProcesses");
        # run the specified procedure synchronously
        &$procedure(@params);
      }
    else
      {
        # we can start an own subthread
        if ($newPid = fork)
          {
            # we are in the main thread, let us store the new pid
            print "PROCESS $newPid COMMAND $procName PARAMETERS:
@params\n"
                if ($DEBUG);
            push(@pidList,$newPid);
          }
        elsif (defined $newPid)
          {
            # let us redirect std input as this might cause some
            # problems (we have had processes which lost their input
            # stream); we do NOT redirect std out and error, as the
            # started subprocesses should still log to these streams
            close STDIN;
            close STDOUT;
            close STDERR;
            open(STDIN,"< /dev/null");
            open(STDOUT,"> /dev/null");
            open(STDERR,"> /dev/null");

            # we are in the new process
            print "Starting new process $$.\n" if ($DEBUG);
            # execute the requested method
            &$procedure(@params);
            print "End of new process $$.\n" if ($DEBUG);
            # the method has terminated, thus finish this thread
           exit 0;
          }
        else
        {
          # we could not start a new process, thus write an error
          # message and start the process synchronously
          errorWrite("Error when forking a new process");
          &$procedure(@params);
        }
      }
  }

#
# waitForProcesses
#
# waitForProcesses waits for all subprocesses of the current process
# to finish
sub waitForProcesses
  {
    my($count);
    
    $count=0;

    print "  Waiting for processes to finish...\n" if ($TRACE);
    while ($count<=$#pidList)
      {
        print "waiting for PIDS: ".join(",",@pidList)."\n" if
($DEBUG);
        if (waitpid($pidList[$count],0) != 0)
          {
            splice @pidList,$count,1;
          }
      }
  }

#
# getNrOfProcesses
#
# getNrOfProcesses returns the number of processes that are currently
# active. It also removes the IDs of finished processes from the
# process id list.
sub getNrOfProcesses
  {
    my($count,$retVal);

    # first, let us check whether any process has already stopped
    $count=0;
    while ($count<=$#pidList)
      {
        # see whether the process has already finished. Note: if the
        # PID is returned, then the process is dead, if -1 is
        # returned, no subprocesses exist.
        if (waitpid($pidList[$count],&WNOHANG) != 0)
          {
            # the process has finished, remove it from the array NOTE:
            # we must NOT increase the counter, as the current element
            # will contain a new value after the split
            splice @pidList,$count,1;
          }
        else
          {
            # we did not remove the current element (since the process
            # is still active), thus increase the counter
            $count++;
          }
      }

    print "Processes: ".join(" ",@pidList)."\n" if ($DEBUG);
    return ($#pidList+1);
  }


Next is the sample program with which I can create deadlocked
processes, either from ssh or sqlplus.

#!/usr/local/bin/perl -w

use myModule;


sub mySort
  {
    system("ssh -d 999 -x -o 'BatchMode yes'  -i identity_file".
           " remote_host ".
           "\"cd target_directory;pwd 2>&1 \"".
           " > tmp/log_$$ 2>&1");
  }

sub mySQL
  {
    $sqlCmd = "\"SELECT COUNT(1) FROM MY_TABLE;\nQUIT\"";
    system("echo ".$sqlCmd."| sqlplus -s username/password".
           " > tmp/log_$$ 2>&1");
  }

$nrOfProc = 10;

sub startSort
  {
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");
    myModule::startProcess(\&mySQL,$nrOfProc,"");
    myModule::startProcess(\&mySort,$nrOfProc,"");

    myModule::waitForProcesses()
  }


sub startSorts
  {
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");
    myModule::startProcess(\&startSort,$nrOfProc,"");

    myModule::waitForProcesses()
  }

startSorts();
print "\n\n\n FINISHED \n\n\n";


------------------------------

Date: Wed, 17 Oct 2001 04:23:37 GMT
From: "Steve Grazzini" <s_grazzini@hotmail.com>
Subject: Re: Entering Name-Value pairs - Still Confused
Message-Id: <dJ7z7.36313$n5.4334540@typhoon.nyc.rr.com>

"Dr. Kokinis" <doctor_pericles@hotmail.com> wrote in message
news:9qiust$h2s$1@coward.ks.cc.utah.edu...

[..]

> Are these cgi-docs somewhere I can find?  I searched google and could not
> find.

[..]

Try typing 'perldoc CGI'
(no quotes, followed by carriage return... )

Or follow this:

http://www.perldoc.com/perl5.6.1/lib/CGI.html

Check the 'debugging' section.





------------------------------

Date: Tue, 16 Oct 2001 23:36:02 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Entering Name-Value pairs - Still Confused
Message-Id: <9qj2fb$lv8$1@slb5.atl.mindspring.net>

"Dr. Kokinis" <doctor_pericles@hotmail.com> wrote in message
news:9qiust$h2s$1@coward.ks.cc.utah.edu...
>
> Yes, but HOW is this done?
>
> For instance, I type:     perl -w mysscript.pl
> It responds with:          (offline mode: enter name=value pairs on
standard
> input)
>
> NOW WHAT???
> In my example would I type
>
> x_name (or would I type "x_name")  then what?  A return and then the
value,
> or a space and then the value???

Dr. K,

Try the following:

Enter the name=value pairs, separating them with "&" and substituting "+"
for spaces., e.g.,

name1=value1&name+2=value+2

A Google search for the string "URL-encoding & Reading CGI Data" will give
you a link that may be helpful to you, namely
http://www.speakeasy.org/~cgires/readdata/. While you're at Google (after
the search), take note of the string in the window of your browser that
shows the URL. You'll see the URL (together with the query string), encoded
as above, and with special characters encoded, e.g.,

http://www.google.com/search?hl=en&q=URL-encoding+%26+Reading+CGI+Data&btnG=
Google+Search

The part after the "?" is what is known as the Query String. The string
"q=URL-encoding+%26+Reading+CGI+Data" should be easily recognized as the
string on which you performed the Google search.

Finally, YOUR query is off-topic for this newsgroup. You should really be
posting it to the newsgroup comp.infosystems.www.authoring.cgi.

Good luck.

Bill Segraves
Auburn, AL






------------------------------

Date: Wed, 17 Oct 2001 12:35:32 +0200
From: "</Marek/>" <mapow@hi.hinet.hr>
Subject: GET and POST problem
Message-Id: <9qjmsk$3erc$1@as201.hinet.hr>

Hi

I have one problem with method=GET and method=POST.
When I set method=POST and use this line: read(STDIN, $data,
$ENV{'CONTENT_LENGTH'});
script can read data, but when method=GET  script can't read enything.
I think that problem is in read(STDIN, $data, $ENV{'CONTENT_LENGTH'}) ;
line.

Help me.






------------------------------

Date: 17 Oct 2001 06:51:20 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: GET and POST problem
Message-Id: <m3wv1ubkuv.fsf@mumonkan.sunstarsys.com>

"</Marek/>" <mapow@hi.hinet.hr> writes:

> Help me.

Help yourself-

  use CGI;

-- 
Joe Schaefer                 "Language is the dress of thought."
                                               -- Samuel Johnson



------------------------------

Date: Wed, 17 Oct 2001 21:55:09 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: GET and POST problem
Message-Id: <slrn9sqsct.di2.mgjv@martien.heliotrope.home>

On Wed, 17 Oct 2001 12:35:32 +0200,
	mapow@hi.hinet.hr <mapow@hi.hinet.hr> wrote:
> Hi
> 
> I have one problem with method=GET and method=POST.
> When I set method=POST and use this line: read(STDIN, $data,
> $ENV{'CONTENT_LENGTH'});
> script can read data, but when method=GET  script can't read enything.
> I think that problem is in read(STDIN, $data, $ENV{'CONTENT_LENGTH'}) ;
> line.

You don't understand the CGI specification. This is not a Perl issue. Go
to some web site and read up on CGI first. 

ObPerl:
You shouldn't be doing this yourself at all. Use the standard CGI
module:

    use CGI;

> Help me.

It will.

Martien
-- 
                                | 
Martien Verbruggen              | Useful Statistic: 75% of the people
                                | make up 3/4 of the population.
                                | 


------------------------------

Date: Wed, 17 Oct 2001 12:10:20 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: GET and POST problem
Message-Id: <3bcd744c.310299682@news.itouch.net>

On Wed, 17 Oct 2001 12:35:32 +0200, "</Marek/>" <mapow@hi.hinet.hr>
wrote:

>Hi
>
>I have one problem with method=GET and method=POST.
>When I set method=POST and use this line: read(STDIN, $data,
>$ENV{'CONTENT_LENGTH'});
>script can read data, but when method=GET  script can't read enything.
>I think that problem is in read(STDIN, $data, $ENV{'CONTENT_LENGTH'}) ;
>line.
>
>Help me.

 If you use the GET method, the form information is sent via the
QUERY_STRING environment variable. 
 If you use the CGI module, you can use the param() function to get
access to the form data without having to worry about the method by
which it was sent.
                             cf


------------------------------

Date: Wed, 17 Oct 2001 15:27:28 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: HELP - QUICK Question!!!
Message-Id: <hG8z7.11$Be1.44076@news.interact.net.au>


"Dr. Kokinis" <doctor_pericles@hotmail.com> wrote in message
news:9qipuj$fje$1@coward.ks.cc.utah.edu...
> How do I manually enter name-value pairs on the command line?
>
> That is, what is the format to be used?  Quotes?
>
> So if I want to pass "name1" with a value of "John"  what would I do?

Usenet is not a medium to create three separate threads for the original
question, just because you didn't get an answer that you understood within
60 minutes.




------------------------------

Date: Wed, 17 Oct 2001 04:15:58 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: HOW TO enter name value pairs manually? - STILL CONFUSED
Message-Id: <x7g08i6gv0.fsf@home.sysarch.com>

>>>>> "K" == Kokinis  <doctor_pericles@hotmail.com> writes:

  >> the cgi.pm docs explain this to you. you can either pass in param/value
  >> pairs on the command line or pass them in to stdin of the script.
  >> 
  >> so the former way can be done with:
  >> 
  >> my_cgi_script foo=bar name=x_name value="test man"
  >> 
  >> and the latter just requires you to type that data to the program after
  >> it runs (it will prompt you for that data). you can also pipe the data
  >> to it from a file or a program using the standard shell redirects and
  K> such.

  K> Yes, but HOW is this done?

i just told you. and read the CGI.pm docs again

  K> I type

  K> perl -w mysscript.pl
  K> It responds with: (offline mode: enter name=value pairs on standard input)

  K> NOW WHAT???

just DO WHAT IT TELLS YOU.

  K> In my example would I type

  K> x_name (or would I type "x_name")  then what?  A return and then the value,
  K> or a space and then the value???

why don't you play with it some? write a simple cgi script that just
echoes its params (that is 2 line of code and i won't show you).

then run it with arguments on the command line just like it shows and i
showed you. then try it with stdin. just enter foo=bar. just like
that. nothing else. then end the input with ^D and watch what
happens. play with it. it is very simple.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


------------------------------

Date: Wed, 17 Oct 2001 09:28:18 +0200
From: Philip Newton <pne-news-20011017@newton.digitalspace.net>
Subject: Re: HOW TO enter name value pairs manually? - STILL CONFUSED
Message-Id: <recqst89idgi1e98l3s726u9i0q2b21vrf@4ax.com>

On Tue, 16 Oct 2001 21:47:20 -0600, "Dr. Kokinis"
<doctor_pericles@hotmail.com> wrote:

> perl -w mysscript.pl
> It responds with: (offline mode: enter name=value pairs on standard input)
> 
> NOW WHAT???
> In my example would I type
> 
> x_name (or would I type "x_name")  then what?  A return and then the value,
> or a space and then the value???

Like it says -- name=value pairs. So I think you would enter

    x_name=Bob Jones

, using an equals sign.

When you're done, arrange for an end-of-file condition on standard
input. For example, in Unix shells, this may involve pressing Ctrl+D, on
MS-DOS, it might be Ctrl+Z or F6.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


------------------------------

Date: Tue, 16 Oct 2001 23:27:31 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: How to restore a filehandle tie correctly?
Message-Id: <3BCCFAA3.6070707@coppit.org>

Benjamin Goldberg wrote:

> David Coppit wrote:
> 
>>Greetings all,
>>
>>I'm trying to update CGI::Cache to play well with FCGI. The problem is
>>that both want to tie to STDOUT.
> 
> Use the Source, Luke.  You don't need to do that, since CGI::Cache
> already takes into account that STDOUT might already be tied.  Take a
> look inside of start().


Um, check out the maintainer's name for CGI::Cache. I think I know what 
I'm talking about. :)

The problem is that what I'm doing inside CGI::Cache to take into 
account the previous tie isn't working correctly with FCGI. The code I 
posted shows the essential problem.


> You do however have a different problem, specifically:
> "Once a page has been cached in this fashion, then a subsequent visit to
> that CGI script will check for an existing cache entry for the given key
> before continuing through the code. If the file exists, then the cache
> file's content is printed to the real STDOUT and the process exits
> before executing the regular CGI code."
> 
> Your bigger problem is that you need to make it NOT exit, and instead do
> another accept loop.


I've already made the change for the next version, which I'll post as 
soon as I get this tie issue resolved. See below for the new semantics.


>     FCGILOOP:
>     while ($q = CGI::Fast->new) {
>         local *CORE::GLOBAL::exit = sub {
>             last FCGILOOP if shift;
>             next FCGILOOP;
>         };
>         my $query = $q->Vars;
>         my $regen = delete $query->{regenerate};
>         CGI::Cache::set_key($query);
>         CGI::Cache::invalidate_cache_entry()
>             if $regen;
>         CGI::Cache::start();


In the new version:

   CGI::Cache::start() or next;

start() will return 0 if it prints cached output. That way you know to 
skip to the next iteration. (And I'd put the ++$COUNTER before the call 
to start, or save the return value of start and do a next after the 
counter increment.)


>         ++$COUNTER;
>         print "Content-type: text/html\n\n";
>         print <<"    EOF";
>         <html>
>         <head><title>Fast CGI</title></head>
>         <body>Counter: $COUNTER PID: $$</body>
>         </html>
>         EOF
>         CGI::Cache::stop();
>     }
> 
> This code is untested.
> Note that normally [in non-fcgi], you wouldn't have to call stop
> explicitly, though here you do.


Yep.

Regards,
David

P.S. Sounds like you're a happy CGI::Cache user. :)


------------------------------

Date: 17 Oct 2001 02:15:58 -0700
From: cyfbosco@yahoo.com (Bosco)
Subject: How to run exec() or system() in a PERL CGI script ?
Message-Id: <cbdf9c15.0110170115.4bfb85cb@posting.google.com>

Basically, what I want to do is when I click the button in a web page,
I will execute a stupid 'rsh' command.

I have tried the following it worked !

@test = `cat .cshrc`;
print "@test\n";

but the following don't !!!

@test = `rsh -l user hostname cat .cshrc`;
print "@test\n";

Please help !


------------------------------

Date: Wed, 17 Oct 2001 11:39:13 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: How to run exec() or system() in a PERL CGI script ?
Message-Id: <b1kqst8qr4nu7cemrid6qa5253eh6oik5m@4ax.com>

On 17 Oct 2001, cyfbosco@yahoo.com (Bosco) wrote:
>Basically, what I want to do is when I click the button in a web page,
>I will execute a stupid 'rsh' command.

>@test = `rsh -l user hostname cat .cshrc`;
>print "@test\n";

Looks more like a CGI/UNIX than a Perl problem.

Have you verified that
- rsh can be found in $PATH when running as a CGI?
- rsh can be executed by your web server user?
- that the remote site accepts a login from your web server user, i.e
  there are the required .rhosts etc entries?

Besides that, I sincerely hope you do understand the implications of
using rsh with a .rhosts file.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


------------------------------

Date: 17 Oct 2001 01:12:18 -0700
From: kenlaird@yahoo.com (Laird)
Subject: How to test the presence of quotes in arguments ?
Message-Id: <94a02505.0110170012.13b7ef72@posting.google.com>

Hello everyone,

cat code.pl
print "$ARGV[0]\t$ARGV[1]\n"

--- end of script

--- Running code.pl

code.pl -name 'name of the person'

 ...

print "$ARGV[0]\t$ARGV[1]\n"

gives

-name	name of the person


The problem is $ARGV[1] strips the quotes ''.
I'd like to make the quotes mandatory ,
that's why I'd like to test 
the presence of quotes in the argument.

Any idea how this could be done?


Ken


------------------------------

Date: 17 Oct 2001 09:03:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to test the presence of quotes in arguments ?
Message-Id: <9qjhhk$3lu$1@mamenchi.zrz.TU-Berlin.DE>

According to Laird <kenlaird@yahoo.com>:
> Hello everyone,
> 
> cat code.pl
> print "$ARGV[0]\t$ARGV[1]\n"
> 
> --- end of script
> 
> --- Running code.pl
> 
> code.pl -name 'name of the person'
> 
> ...
> 
> print "$ARGV[0]\t$ARGV[1]\n"
> 
> gives
> 
> -name	name of the person
> 
> 
> The problem is $ARGV[1] strips the quotes ''.
> I'd like to make the quotes mandatory ,
> that's why I'd like to test 
> the presence of quotes in the argument.
> 
> Any idea how this could be done?

Not at all, at least there is nothing you can do about it in your
Perl script.  The quotes are consumed by the shell before the argument
appears in @ARGV.  Under some circumstances, a Perl program can conclude
that quotes (or some quoting mechanism) has been used because a parameter
contains shell metacharacters (such as blanks).  There is no way to tell
that there have been no quotes.

Anno


------------------------------

Date: 17 Oct 2001 09:07:02 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: How to test the presence of quotes in arguments ?
Message-Id: <slrn9sqi5d.85e.bernard.el-hagin@gdndev25.lido-tech>

On 17 Oct 2001 09:03:48 GMT, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
wrote:
> According to Laird <kenlaird@yahoo.com>:
>> Hello everyone,
>> 
>> cat code.pl
>> print "$ARGV[0]\t$ARGV[1]\n"
>> 
>> --- end of script
>> 
>> --- Running code.pl
>> 
>> code.pl -name 'name of the person'
>> 
>> ...
>> 
>> print "$ARGV[0]\t$ARGV[1]\n"
>> 
>> gives
>> 
>> -name	name of the person
>> 
>> 
>> The problem is $ARGV[1] strips the quotes ''.
>> I'd like to make the quotes mandatory ,
>> that's why I'd like to test 
>> the presence of quotes in the argument.
>> 
>> Any idea how this could be done?


I don't think so. You *could* try to cheat when calling your script:


code.pl -name "'name of the person'"


But I don't know if that's what you want.


Cheers,
Bernard


------------------------------

Date: Wed, 17 Oct 2001 03:20:30 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to test the presence of quotes in arguments ?
Message-Id: <3bcd5b6f@news.microsoft.com>

"Laird" <kenlaird@yahoo.com> wrote in message
news:94a02505.0110170012.13b7ef72@posting.google.com...
> cat code.pl
> print "$ARGV[0]\t$ARGV[1]\n"
> --- end of script
>
> --- Running code.pl
> code.pl -name 'name of the person'
>
> print "$ARGV[0]\t$ARGV[1]\n"
>
> gives
>
> -name name of the person
>
> The problem is $ARGV[1] strips the quotes ''.

No, it doesn't. It is the shell which removes the quotes. The Perl
interpreter never has a chance to see them.

> I'd like to make the quotes mandatory ,
> that's why I'd like to test
> the presence of quotes in the argument.

You need to escape the quote
- code.pl -name \'name of the person\'

However this will give you an @ARGV with four elements:
    ["'name", "of", "the", "person'"]

If you want this as one item then you need to tell the shell that these four
words are a single argument by---guess what---enclosing the argument in
quotes:
- code.pl -name '\'name of the person\''
or
- code.pl -name "\'name of the person\'"

Not sure if this will make your users happier ;-)

jue





------------------------------

Date: Wed, 17 Oct 2001 08:34:21 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: how to write to different host+port on one socket?
Message-Id: <la9qsto4pdpvbah324k6ib676o2cg67thd@4ax.com>

On 16 Oct 2001 11:00:59 -0700, erskine-google@sourceworks.com (Thomas
Erskine) wrote:

>What am I doing wrong?  Here's my attempt:

>$sock->send( 'xxx1', 0, '205.189.80.197:10002') or

That should be

  my $hisiaddr = inet_aton("205.189.80.197");
  my $hispaddr = sockaddr_in( 10002, $hisiaddr );
  $sock->send( 'xxx1', 0, $hispaddr ) or die "Error sending: $!\n";

See "UDP: Message Passing" in the perlipc manpage for details.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1944
***************************************


home help back first fref pref prev next nref lref last post