[22811] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5032 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 23 21:10:31 2003

Date: Fri, 23 May 2003 18:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 23 May 2003     Volume: 10 Number: 5032

Today's topics:
        Return a value from Perl <randy.harris@nospam.net>
    Re: Return a value from Perl <abigail@abigail.nl>
    Re: Return a value from Perl <robert.j.sipe@boeing.com>
    Re: Spawning self - a better way? (David Efflandt)
        Using GD::Graph in a CGI <null@null.com>
    Re: Using GD::Graph in a CGI <willis_31_40@yahoo.com>
    Re: Using GD::Graph in a CGI <spam@thecouch.homeip.net>
        Where should I look? <porter96@lycos.com>
    Re: Where should I look? <mbudash@sonic.net>
    Re: Where should I look? <nospam@raytheon.com>
    Re: Where should I look? <porter96@lycos.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 23 May 2003 21:10:39 GMT
From: "Randy Harris" <randy.harris@nospam.net>
Subject: Return a value from Perl
Message-Id: <i7wza.2895$4G.1147644@newssvr28.news.prodigy.com>

How can I return a value from a Perl program so that I can use it like a
function?  Return does this for a sub but can't be used outside a sub, and I
would like to return a value to the program that called the Perl program.

-- 
Randy Harris




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

Date: 23 May 2003 22:10:07 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Return a value from Perl
Message-Id: <slrnbct71v.kuj.abigail@alexandra.abigail.nl>

Randy Harris (randy.harris@nospam.net) wrote on MMMDLII September
MCMXCIII in <URL:news:i7wza.2895$4G.1147644@newssvr28.news.prodigy.com>:
$$  How can I return a value from a Perl program so that I can use it like a
$$  function?  Return does this for a sub but can't be used outside a sub, and I
$$  would like to return a value to the program that called the Perl program.


You can't, and that's not Perl's fault. That's because the OS is designed
that way. On Unix, a process can have one of 256 exit values: 8 bits, 
and nothing more. Other OSses work similar.

If you want to pass more information, you'd need to do something else.
Communicate via a pipe, for instance.

See 'man perlipc'.



Abigail
-- 
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
          for (s;s;s;s;s;s;s;s;s;s;s;s)
              {s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'


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

Date: Fri, 23 May 2003 21:58:12 GMT
From: "Robert" <robert.j.sipe@boeing.com>
Subject: Re: Return a value from Perl
Message-Id: <HFD10y.IIv@news.boeing.com>

Try this:

$status = system("your perl program");

# shift status 8 places

print "Status is ", $status >> 8," \n";

if (($status >> 8) != 0) {
   print "Darn\n";
}

"Randy Harris" <randy.harris@nospam.net> wrote in message
news:i7wza.2895$4G.1147644@newssvr28.news.prodigy.com...
> How can I return a value from a Perl program so that I can use it like a
> function?  Return does this for a sub but can't be used outside a sub, and
I
> would like to return a value to the program that called the Perl program.
>
> --
> Randy Harris
>
>




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

Date: Fri, 23 May 2003 21:47:44 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Spawning self - a better way?
Message-Id: <slrnbct5o0.gkq.efflandt@typhoon.xnet.com>

On Fri, 23 May 2003 14:46:26 GMT, Tweetie Pooh <tp601553@cia.gov> wrote:
>    I asked a question here earlier this week and the solution worked.  We it 
> did sort of.  The problem is not in perl though.
> 
> Essentially I had a server that spawned children on connection, not unusual.  
> The other side though did not send data as requested and didn't always make 
> the connection properly.  Change of tack.
> 
> Now my side connects out and listens on the remote port, collecting data, 
> processing and passing on.
> 
> The program reads a list of remote host ip's (and port) into an array and 
> does some other setup stuff.
> 
> If no command line parameters are present it assumes to be the daddy and 
> enters a loop using system() to call itself with each ip/port combination as 
> background processes after which it exits.
> 
> If command line parameters are present the above loop is bypassed and the 
> program opens log file and output port then enters an infinite loop in which 
> it connects to the remote site.  If connect is OK it loops reads data and 
> processes yada yada yada.

See 'perldoc perlipc' which has examples of client/server scripts 
including servers that spawn a child to handle each connection, then the 
parent immediately goes back to waiting for the next new connection.  
Although, it sounds like you want a parent client that forks a child 
client for each of a list of connections.  There is no reason I can think 
of to use system() for that.

There is also an example of forking and daemonizing a child (disassociated
it from its parent) so it can go off and do its own thing.  I use that for
a Perl daemon that forks into the background and uses LWP to monitor the
dynamic WAN IP of my router (and reports to syslogd to log occasional
status or if anything changes, along with updating DNS).  Although, I only
do it for a single process, it could just as easily be done for a list of
children.

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Fri, 23 May 2003 23:58:07 +0200
From: "Fernando" <null@null.com>
Subject: Using GD::Graph in a CGI
Message-Id: <bam5hc$mkj$1@news.ya.com>

Hi all!

Im using GD::Graph in a CGI to show a graphic whith values taken from a
form.

When i click submit button, the graphic that appears is not the one with the
values i have filled, is the one generated before that one.

So, for example, if i set values 10, 20 and 30, a graphic whith these values
represented is shown. I click back button, and then i fill new values, for
example 50, 50, 50.
When i click submit, the graphic that appears is the one showing 10, 20 and
30, and if i click refresh, then it shows the new one, whith values 50, 50
and 50.

Maybe this is a problem in the browser, but how can i force it to represent
allways the new graphic?

Writing the graphic to a png file with a random name, and then open it whith
<img src="graphic$random.png"> is a solution that works, but filling the
directory with many png files doesnt seem to be an 'elegant' solution.
Moreover, if for any reason two consecutive random numbers are equal, the
file that is shown is the previous, once again.

Any suggestions?

Thanks a lot

Fernando
Madrid, Spain




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

Date: Fri, 23 May 2003 22:35:30 GMT
From: w i l l <willis_31_40@yahoo.com>
Subject: Re: Using GD::Graph in a CGI
Message-Id: <6h8tcv8eqj3qb738sv2ncd8ikvinot2v7m@4ax.com>

On Fri, 23 May 2003 23:58:07 +0200, "Fernando" <null@null.com> wrote:

>Hi all!
>
>Im using GD::Graph in a CGI to show a graphic whith values taken from a
>form.
>
>When i click submit button, the graphic that appears is not the one with the
>values i have filled, is the one generated before that one.
>
>So, for example, if i set values 10, 20 and 30, a graphic whith these values
>represented is shown. I click back button, and then i fill new values, for
>example 50, 50, 50.
>When i click submit, the graphic that appears is the one showing 10, 20 and
>30, and if i click refresh, then it shows the new one, whith values 50, 50
>and 50.
>
>Maybe this is a problem in the browser, but how can i force it to represent
>allways the new graphic?
>
>Writing the graphic to a png file with a random name, and then open it whith
><img src="graphic$random.png"> is a solution that works, but filling the
>directory with many png files doesnt seem to be an 'elegant' solution.
>Moreover, if for any reason two consecutive random numbers are equal, the
>file that is shown is the previous, once again.
>
>Any suggestions?
>
>Thanks a lot
>
>Fernando
>Madrid, Spain
>


You can force the browser to hit the server and not get local cache by
using an HTML meta tag, I forget which one tho... are you using IE?
See if you get the same results in Mozilla

w i l l


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

Date: Fri, 23 May 2003 18:47:53 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Using GD::Graph in a CGI
Message-Id: <xyxza.43236$7E5.143971@wagner.videotron.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Fernando wrote:
> Hi all!
> 
> Im using GD::Graph in a CGI to show a graphic whith values taken from a
> form.
> 
> When i click submit button, the graphic that appears is not the one with the
> values i have filled, is the one generated before that one.
> 
> So, for example, if i set values 10, 20 and 30, a graphic whith these values
> represented is shown. I click back button, and then i fill new values, for
> example 50, 50, 50.
> When i click submit, the graphic that appears is the one showing 10, 20 and
> 30, and if i click refresh, then it shows the new one, whith values 50, 50
> and 50.
> 
> Maybe this is a problem in the browser, but how can i force it to represent
> allways the new graphic?
> 
> Writing the graphic to a png file with a random name, and then open it whith
> <img src="graphic$random.png"> is a solution that works, but filling the
> directory with many png files doesnt seem to be an 'elegant' solution.
> Moreover, if for any reason two consecutive random numbers are equal, the
> file that is shown is the previous, once again.
> 
> Any suggestions?

Create a second CGI, the job of which is to generate the image and send 
it directly to the browser (with the appropriate content-type of course).

Then use a reference to that second CGI as your <img> tag, Example:
<img src="/cgi-bin/generategraph.cgi?a=10&b=20&c=30">

Best of luck.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+zqUdeS99pGMif6wRAlklAKCLI8e7e+BXynJ3a21r7Dsed3RwhACg9M0Q
JhwMdS7BaoERh/KRl22pICQ=
=voQH
-----END PGP SIGNATURE-----



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

Date: Fri, 23 May 2003 13:15:59 -0500
From: "Steve" <porter96@lycos.com>
Subject: Where should I look?
Message-Id: <vcsparj168ad05@corp.supernews.com>

I have an html form, that runs a perl script that I want to display the
results in a javascript popup window.  Or to say it another way... Hit the
submit button and a window comes up with the results of my Perl script in
it.

I can use the Target=_blank in the form commands, but I need the javascript
to do things like toolbar=no and the like.

I've searched and can't find anything that works.  This is really html/java
but I figured someone here might have done this before.

Where should I look?

Steve




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

Date: Fri, 23 May 2003 18:19:18 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Where should I look?
Message-Id: <mbudash-653114.11191823052003@typhoon.sonic.net>

In article <vcsparj168ad05@corp.supernews.com>,
 "Steve" <porter96@lycos.com> wrote:

> I have an html form, that runs a perl script that I want to display the
> results in a javascript popup window.  Or to say it another way... Hit the
> submit button and a window comes up with the results of my Perl script in
> it.
> 
> I can use the Target=_blank in the form commands, but I need the javascript
> to do things like toolbar=no and the like.
> 
> I've searched and can't find anything that works.  This is really html/java
> but I figured someone here might have done this before.
> 
> Where should I look?
> 
> Steve
> 
> 

look into javascript's window.open built-in function and its associated 
options:

http://www.devguru.com/technologies/ecmascript/quickref/win_open.html

-- 
Michael Budash


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

Date: Fri, 23 May 2003 15:27:49 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Where should I look?
Message-Id: <4vvza.3387$c6.3298@bos-service2.ext.raytheon.com>

Steve wrote:
> I have an html form, that runs a perl script that I want to display the
> results in a javascript popup window.  Or to say it another way... Hit the
> submit button and a window comes up with the results of my Perl script in
> it.

This description sounds to me like you want to hit submit and have the 
results show up in -- yours words -- a "javascript window," which I take 
to be like an alert box.  If this is the case, submit your form, and 
have the results of your perl script (CGI?) send back the form as it 
looks on the submit with a JavaScript preamble written to the top of the 
HTML you send back:

<html>
<head>
<script>
<!--
    alert(
       'Line 1\n' +
       'Line 2\n' +
       'Line 3, etc.\n'
    );
//-->
</script>
</head> <!-- etc. -->

Or use an onLoad() event in the body tag to run a named function of your 
choosing.  When the page loads from your submit, the JavaScript will run 
and popup a box over the top of your form.  It takes a round-trip to the 
server, but works.

> 
> I can use the Target=_blank in the form commands, but I need the javascript
> to do things like toolbar=no and the like.
> 

Now THIS sounds like you want to hit submit and have the result show up 
in another BROWSER window *using* JavaScript (since you mention the 
"toolbar=no" option.)  This is different.

The way I do it is this way:

(1) In the <form> tag, I have a "target='_popup'"  "_popup" is a made up 
name; it can be anything:

<form name="frmPopup" method="POST" target="_popup">

Note that there is no "action=" clause in the form tag.  That comes in 
play here:

(2) I have a JavaScript routine that creates the _popup window and does 
the submit on a link click (could easily be a button click as well.)

<script>
<!--
    function Popup( strURL ) {
       form = document.frmPopup;
       winPopup = window.open( '', '_popup', 
'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=710,height=525' 
);
       form.action = strURL;
       form.submit();
       winPopup.focus();
       return false;
    }
//-->
</script>

(3) Construct your links (or buttons) to use the "onClick" event to call 
the Popup function.  Place your target CGI in the Popup call in the 
link, and the results of you CGI will show up in another browser window:

<a href="#default" onClick="return Popup( 
'/cgi-bin/my-target-script.cgi' );">Run My Script In Another Window</a>


There may be a simpler way, and in fact I know I derived this from 
something a bit simpler I saw somewhere, but put it together this way 
for a reason.  I'm sure exactly why.  (I've just written to too much 
stuff to remember WHY I've done certain things at this point.)  But I 
know this works.

> I've searched and can't find anything that works.  This is really html/java
> but I figured someone here might have done this before.
> 
> Where should I look?
> 

If this is not clear perhaps someone can clarify.  This is of course 
very loosely related to Perl since there is certainly more JavaScripting 
involved here than Perl, but again, I know it works.

I think the "return false;" in the Popup() function keeps "#default" 
from showing up in the status window.  Again, can't remember for sure, 
but "return false;" is there for a reason.  The results of the CGI will 
be in another broswer window.  Adjust the parameters on window.open() 
call in Popup() to suit your tastes.

Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN

email: olivec(AT)indy(DOT)raytheon(DOT)com



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

Date: Fri, 23 May 2003 16:49:24 -0500
From: "Steve" <porter96@lycos.com>
Subject: Re: Where should I look?
Message-Id: <vct5qv17c33ndc@corp.supernews.com>

Thanks for the help everyone.  Between Michael sending me to a good
description of the java window.open stuff and Chris pointing out a couple of
form/html things ... I've got it working.  Thanks for taking the time!

Best Regards,
Steve




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

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 5032
***************************************


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