[16214] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3626 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 11 18:20:56 2000

Date: Tue, 11 Jul 2000 15:20:36 -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: <963354035-v9-i3626@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 11 Jul 2000     Volume: 9 Number: 3626

Today's topics:
    Re: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2. (Charles Wilt)
    Re: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2. <bart.lateur@skynet.be>
    Re: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2. (Charles Wilt)
        Open and print file? <arild@langtind.no>
    Re: Perl CGI for Remote Control? <mnarvaja@ar.geocities.xyz.com>
    Re: PPM problems <greg2@surfaid.org>
        Printing web pages aaronp243@my-deja.com
    Re: Printing web pages u0107@cheerful.com
    Re: Printing web pages aaronp243@my-deja.com
    Re: Re-directing dos stderr stdout to file. How? (Malcolm Dew-Jones)
    Re: running system command as root from perl <troyNO@SPAM.troysplace.net>
    Re: running system command as root from perl <troyNO@SPAM.troysplace.net>
    Re: running system command as root from perl ynotssor@my-deja.com
    Re: running system command as root from perl kmhanser@my-deja.com
    Re: running system command as root from perl (brian d foy)
        scripting question <tjturner@chpc.utah.edu>
    Re: scripting question newsposter@cthulhu.demon.nl
    Re: slow learner needs help with splice () <stephen_carpenter@hp.com>
    Re: split NONSENSE <bart.lateur@skynet.be>
    Re: String length? (John Stanley)
    Re: String length? <russ_jones@rac.ray.com>
    Re: stupid perl question <eprom007@hotmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 11 Jul 2000 18:13:27 GMT
From: charles.0272@worldnet.no.spam.att.net (Charles Wilt)
Subject: Re: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2.pl")
Message-Id: <MPG.13d52e894f77a36d989928@netnews.worldnet.att.net>

In article <jeimms0maj3qegq799bconc59q9a9d73gr@4ax.com>, 
bart.lateur@skynet.be says...

<snip>
> Fair enough.
> 
> >From other posts in this group and from the documentation, I understand 
> >that the following method would work also
> >
> >do 'prog2.pl';
> >
> >Seems to me this is the better way, is this true?
> 
> It's in a different league altogether. The second script is run while
> sharing all variables with the original script. It may be what you want,
> but it may be annoying too, if both scripts use a lot of global
> variables then they may end up changing each-other's variables.

I don't think it would be a problem, we've got a use strict; and all 
variables are declared as my $var.

> 
> >What about the return code from prog2.pl?
> 
> Eh? The result of the do statement is the last expression evaluated in
> that other script. You should also check $@ to see if something went
> wrong.

Not quite sure what you mean, the last line of prog2.pl would be 
exit 0;
 or if there is a problem 
exit 1;  

Could I do the following:
$rc = do 'prog2.pl';

What should I look for in $@

> 
> >Lastly, it may matter that prog2.pl could be called from prog1.pl or 
> >directly from the command line.
> 
> Try caller(). If run from the command line, caller() will return an
> empty list (false), if tested in the main body of the script. It will be
> true (a list of 3 items if in list context: package = "main", script
> name and line number) if called through do().
> 
> 

Thanks, I try to keep that in mind.  I don't think I need it here though, 
since it doesn't matter from where it was called.  I just thought it 
might matter as far as how I call prog2.pl from prog1.pl that prog2.pl is 
also called from the command line.

Thanks for you help,
Charles


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

Date: Tue, 11 Jul 2000 21:15:27 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2.pl")
Message-Id: <c9smmskv2a7b4p05u8h4h7dq8rfi9gt6m1@4ax.com>

Charles Wilt wrote:

>Not quite sure what you mean, the last line of prog2.pl would be 
>exit 0;
> or if there is a problem 
>exit 1;  
>
>Could I do the following:
>$rc = do 'prog2.pl';
>
>What should I look for in $@

Well, if you do

	die "Horrible death!";

in prog2.pl, this is basically the text you would get in $@ (plus some
extra automatically added stuff, starting with "at" and ending with a
newline, and containing the filename and the line number.

Apparently, if you do "exit" inside a "do" script, then it won't return
to the original script! Yuck!

-- 
	Bart.


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

Date: Tue, 11 Jul 2000 20:11:55 GMT
From: charles.0272@worldnet.no.spam.att.net (Charles Wilt)
Subject: Re: Newbie, do 'prog2.pl' vs. $rc = system("perl prog2.pl")
Message-Id: <MPG.13d54a4aefe6dadb989929@netnews.worldnet.att.net>

In article <c9smmskv2a7b4p05u8h4h7dq8rfi9gt6m1@4ax.com>, 
bart.lateur@skynet.be says...
> Charles Wilt wrote:
> 
> >Not quite sure what you mean, the last line of prog2.pl would be 
> >exit 0;
> > or if there is a problem 
> >exit 1;  
> >
> >Could I do the following:
> >$rc = do 'prog2.pl';
> >
> >What should I look for in $@
> 
> Well, if you do
> 
> 	die "Horrible death!";
> 
> in prog2.pl, this is basically the text you would get in $@ (plus some
> extra automatically added stuff, starting with "at" and ending with a
> newline, and containing the filename and the line number.
> 
> Apparently, if you do "exit" inside a "do" script, then it won't return
> to the original script! Yuck!
> 
> 

Ok, I think I understand that.  Actually, the exit thing might be 
alright, because all the calling program does is abort anyway.

Do you know of any arguments for or against one method or the other?

Thanks,
Charles


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

Date: Tue, 11 Jul 2000 21:36:59 GMT
From: "langtind" <arild@langtind.no>
Subject: Open and print file?
Message-Id: <%rMa5.2548$Dxe.186298368@news.telia.no>

Hi!
I just wonder how I open and print a file (with Perl) with several lines. I
have only made to print out the first line.
Yes, I know you think it's simple, but I need some help.

Thanks,
Trond Aage




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

Date: Tue, 11 Jul 2000 15:28:25 -0300
From: Marcelo Narvaja <mnarvaja@ar.geocities.xyz.com>
Subject: Re: Perl CGI for Remote Control?
Message-Id: <396B6749.53F4069E@ar.geocities.xyz.com>

Try this implementacion of CGI.pm ,

#!/usr/local/bin/perl

use CGI;
$query = new CGI;
print $query->header;
$TITLE="Commands Test";

# We use the path information to distinguish between calls
# to the script to:
# (1) create the frameset
# (2) create the query form
# (3) create the query response

$path_info = $query->path_info;

# If no path information is provided, then we create
# a side-by-side frame set
if (!$path_info) {
    &print_frameset;
    exit 0;
}

# If we get here, then we either create the query form
# or we create the response.
&print_html_header;
&print_query if $path_info=~/query/;
&print_response if $path_info=~/response/;
&print_end;


# Create the frameset
sub print_frameset {
    $script_name = $query->script_name;
    print <<EOF;
<html><head><title>$TITLE</title></head>
<frameset cols="50,50">
<frame src="$script_name/query" name="query">
<frame src="$script_name/response" name="response">
</frameset>
EOF
    ;
    exit 0;
}

sub print_html_header {
    print $query->start_html($TITLE);
}

sub print_end {
    print qq{<P><hr><A HREF="cgi_docs.html">Go to the documentation</A>};
    print $query->end_html;
}

sub print_query {
    $script_name = $query->script_name;
    print "<H1>Frameset Query</H1>\n";
    print
$query->startform(-action=>"$script_name/response",-TARGET=>"response");
    print "Type the command ",$query->textfield('cmd');
    "<P>";
    print $query->submit;
    print $query->endform;
}

sub print_response {
    $stout = "/tmp/stout.$$";
    $sterr = "/tmp/sterr.$$";
    print "<H1>Frameset Result</H1>\n";
    unless ($query->param) {
 print "<b>No command submitted yet.</b>";
 return;
    }
    $cmd = $query->param(cmd);
    system("$cmd > $stout 2>$sterr");
    print "<B><I>Standard output:</I></B> <BR><XMP>",`cat
$stout`,"</XMP>\n";
    print "<P><B><I>Standard error:</I></B> <BR><XMP>",`cat
$sterr`,"</XMP>\n";
    unlink "$stout";
    unlink "$sterr";
}



Darren Ward wrote:

> Hi All,
>
> I'm trying to find a way to have a CGI window/frame to act as if it was
> an interactive program running on the web server.
>
> Specifically telnet and something like minicom to control a serial
> device.
> So it would appear that you have a shell prompt within a CGI frame and
> you can type in commands etc just like normal.
>
> So has anyone any thoughts on how to re-route a command line interface
> via a CGI? Any modules?
>
> Darren
>
> PS Solution will be posted to the groups.





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

Date: Tue, 11 Jul 2000 20:47:22 +0100
From: Greg Griffiths <greg2@surfaid.org>
To: =?iso-8859-1?Q?K=E5re?= Olai Lindbach <barbr-en@online.no>
Subject: Re: PPM problems
Message-Id: <396B79CA.329AEF73@surfaid.org>

> READ THIS FIRST!
> *By the way*, (also pointed out by 'Rob'), did you read importent info about
> programs etc you had to
> install prior and patches after installation of ASPerl build 613? It's
> necessary to
> follow the receipt! I see you have done the ppmfix.
>

As far as I could tell on a clean win98 build you just needed to instlal the MS
Installer and then AP 613 and then the PPM hotfix.

>
> Strange that you have none ppm.log, but you have maybe never got the ppm
> running on that machine?!.

The error seems to occur during the PPM module, so I guess it dies before it
writes the log ?

>
> I use ActiveState perl 5.6.0 on my win98. Every time I run ppm (well, not
> often), ppm makes a PPM.LOG (Capital letters) in current directory. I run
> ppm using MSDOS command shell window.
>
> -Contents looks like this:
> -snip-
> ppm.bat: starting up... at Tue Jul  4 19:00:57 2000
> ppm.bat: starting up... at Tue Jul  4 19:01:18 2000
> ppm.bat: Wrote config file at Tue Jul  4 19:08:47 2000
> ppm.bat: starting up... at Tue Jul  4 19:08:53 2000
> ppm.bat: valid_URL_or_file: local/parallell-port.pdd.ppd is not valid at Tue
> Jul  4 19:12:31 2000
> ppm.bat: Could not locate a PPD file for package parallell-port.pdd at Tue
> Jul  4 19:12:31 2000
> ppm.bat: valid_URL_or_file: local/win32-serialport.ppd.ppd is not valid at
> Tue Jul  4 19:13:35 2000
> ppm.bat: Could not locate a PPD file for package win32-serialport.ppd at Tue
> Jul  4 19:13:35 2000
> ppm.bat: Removed repository HASH(0x93a157c) at Tue Jul  4 19:15:07 2000
> -cut-
>
> By the way, when I once set the repository using embracing one parameter
> with ", ppm also gave up and died. I had to go directly into config-file:
> '<perl-dir>\site\lib\ppm.xml' and correct it using an editor.
>
> There is an configPPM.pl, which most likely is run on installation, maybe
> that have failed. I dare not test it on my machine, since ppm works. Maybe
> others have something to add here. I feel ppm is not very well documented,
> foolproofed nor tested, although it's an importent program for win-users.
> Well, it's possible to do the work yourself, putting all the files in right
> dirs......
>
> Also, look into PPMConfig.html. There you might compare your ppm.xml against
> a sample. (If you are familiar to html/xml syntax)
>
> I *think* your problem lies in your "ppm.xml" -file, if you have clean
> conscience about the patches etc.
>

Have rebuild this using ppm genconfig and it still failed.

>
> Maybe it's easiest to remove ASPerl using
> Start->Setup->Controlpanel->Add/remove programs   (Hope I'm correct, I use
> an norwegian version of win98), and reinstall it all together. Since your
> ppm isn't working, you probably havent installed much libs anyway.

have reinstalled twice with 519 and failed, each time using a clean Win98 build
(no extras, just Win and Office), reverted back to AP 509 and have no problems -
except the data and time I've lost to get back to where I was before I started.


>
>
> Regards
>
> --
> mvh
> Kåre Olai Lindbach
> (LLP - 955626397 MVA)
> + 47 61282501(home/job)
> + 47 61282502(fax)
> barbr-en@online.no
> # a perl programming man (ppm), it was?!.......;-)



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

Date: Tue, 11 Jul 2000 19:29:46 GMT
From: aaronp243@my-deja.com
Subject: Printing web pages
Message-Id: <8kfsig$2s1$1@nnrp1.deja.com>

Hi!  I am trying to print a web page using perl as if the web page were
being printed from netscape.  I want to do this with perl because I have
to print out many of the web pages!  Any ideas would be appreciated!
Thanks in advance.

-Aaron


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 20:34:06 GMT
From: u0107@cheerful.com
Subject: Re: Printing web pages
Message-Id: <8kg0bt$5s4$1@nnrp1.deja.com>



This is how I accomplished printing a page.

I use Perl to create the HTML code which is displayed using the browser.

In the browser, the following javascript code is used

function print_a_page ()
{
window.print()
}


I use
print 'function print_a_page()';
print "\n";
print '{';
etc.....


and a button in the html code has

onClick="return print_a_page()"

All of the javascript code can be in a common file which is included.

hope this helps

Uttam

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

In article <8kfsig$2s1$1@nnrp1.deja.com>,
  aaronp243@my-deja.com wrote:
> Hi!  I am trying to print a web page using perl as if the web page
were
> being printed from netscape.  I want to do this with perl because I
have
> to print out many of the web pages!  Any ideas would be appreciated!
> Thanks in advance.
>
> -Aaron
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 20:56:18 GMT
From: aaronp243@my-deja.com
Subject: Re: Printing web pages
Message-Id: <8kg1l9$6t8$1@nnrp1.deja.com>

In article <8kg0bt$5s4$1@nnrp1.deja.com>,
  u0107@cheerful.com wrote:
>
>
> This is how I accomplished printing a page.
>
> I use Perl to create the HTML code which is displayed using the
browser.
>
> In the browser, the following javascript code is used
>
> function print_a_page ()
> {
> window.print()
> }
>
> I use
> print 'function print_a_page()';
> print "\n";
> print '{';
> etc.....
>
> and a button in the html code has
>
> onClick="return print_a_page()"
>
> All of the javascript code can be in a common file which is included.
>
> hope this helps
>
> Uttam
>
> ----------------
>
> In article <8kfsig$2s1$1@nnrp1.deja.com>,
>   aaronp243@my-deja.com wrote:
> > Hi!  I am trying to print a web page using perl as if the web page
> were
> > being printed from netscape.  I want to do this with perl because I
> have
> > to print out many of the web pages!  Any ideas would be appreciated!
> > Thanks in advance.
> >
> > -Aaron
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

That is not exactly what I had in mind.  I am trying to print the pages
without having to do anything.  I have sooo many pages to print that
clicking on stuff would make it take too long.  Thanks anyway though!

--Aaron


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 11 Jul 2000 13:20:00 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Re-directing dos stderr stdout to file. How?
Message-Id: <396b8170@news.victoria.tc.ca>

Steve A. Taylor (an400@freenet.carleton.ca) wrote:
: On Mon, 10 Jul 2000 02:50:09 GMT, Bob Walton
: <bwalton@rochester.rr.com> wrote:

: >"Steve A. Taylor" wrote:
: >...
: >> Thanks. It still surprises me that the author(s) of find2perl created
: >> a batch file rendered  .. difficult or impractical .. because the
: >> output I need is staring at me on the screen (Posting to CLPModules
: >> may be another answer).
: >
: >Well, I think the find2perl folks probably did about as well as can be
: >done and still have something that will work when you type "find2perl
: >..." in DOS.  You could nab the Perl program out of find2perl.bat (it is
: >just a short .bat wrapper around a standard Perl program that runs as-is
: >under Unix with no redirection problems) and then execute it as "perl
: >find2perl.pl ...", which isn't quite as nice to type, but should permit
: >redirection.  If you want to castigate someone, castigate Micro$loth for
: >the incredibly lousy job they did with their command "shell".
: >-- 
: >Bob Walton

: No, not castigate -- understand the purpose and functionality of batch
: files distributed with Perl; which would of course be easier if dos
: was more unix.. The find2perl.pl script shows up in the source of
: 5.60.

Are you running NT? 

If it's NT then you should be able to redirect the output of your batch
file.  Also works for stderr - use  2>  to redirect stderr.

If it's non-NT (95/98) then that's just the way DOS batch files work.  

	command /c yourfile.bat > output  

can be used for any batch file to get its standard output.
(I can't test that line right now)



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

Date: Wed, 12 Jul 2000 07:26:13 -0500
From: "Troy Bell" <troyNO@SPAM.troysplace.net>
Subject: Re: running system command as root from perl
Message-Id: <PhMa5.9$M53.2541706@news.interact.net.au>

In article <brian-ya02408000R1007002308000001@news.panix.com>,
brian@smithrenaud.com (brian d foy) wrote:
> In article <8ke1rg$nf7$1@nnrp1.deja.com>, ynotssor@my-deja.com posted:
> 
>> The killhttpd program is a trivial script:
>> 
>> #!/bin/sh
>> kill -HUP `ps -aef | grep httpd | grep -v grep | awk '{print $2}'`
> 
> that won't work for many reasons, and it's just dumb.  if you had read
> the apache docs, you would have discovered that you want the USR1 signal
> and the PID file.
> 
> 
> kill -USR1 `cat /etc/httpd.pid`
> 

Hrm, why go to all that trouble, when you can just run your apachectl
script?

If you really want to create a security hazard (heh) install suid perl and
do the following:

Instead of #!/usr/bin/perl, use #!/usr/bin/suidperl

Make sure your script is owned by root, and chmod u+s your script.

If you want to reload apache's config file, the best way to do that, IMHO,
is by using what apache recommends:

system("/usr/local/apache/bin/apachectl graceful");

Or, since you want to see if there is any errors or such, you might want
to:

print "Output of apachectl:<br><br>\n"; open(APACHECTL,
"/usr/local/apache/bin/apachectl graceful |"); while (<APACHECTL>) {
    chop; print "$_\n";
}
close(APACHECTL);

Maybe you should use the same code above, but replace "graceful" with
"configtest" as another button on your page to check the config file
before you restart?

Anyhoo, just a few suggestions.

(Also, make sure this isn't visible to the outside world, eg. on an
internal net, .htaccess'd etc. etc.)

Troy.



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

Date: Wed, 12 Jul 2000 07:32:23 -0500
From: "Troy Bell" <troyNO@SPAM.troysplace.net>
Subject: Re: running system command as root from perl
Message-Id: <AnMa5.10$9%2.2415702@news.interact.net.au>

In article <PhMa5.9$M53.2541706@news.interact.net.au>, "Troy Bell"
<troyNO@SPAM.troysplace.net> wrote:

> print "Output of apachectl:<br><br>\n"; open(APACHECTL,
> "/usr/local/apache/bin/apachectl graceful |"); while (<APACHECTL>) {
>     chop; print "$_\n";
> }
> close(APACHECTL);

*sigh* I hate when your news reader does that.

One thing I failed to mention, since apachectl prints to STDERR for some
things, your code will probably want to look like:

    ## Run apache's configtest to see if everything's ok
    print "Output of apachectl configtest:\n<br><br>\n";
    open (APACHECTL, "/usr/sbin/apachectl configtest 2>&1|");
    while (<APACHECTL>) {
	print "$_\n<br>\n";
    }
    print "<br>";
    close(APACHECTL);

That is, if you do decide to do a config test first ;)

I take it you know what the "2>&1" is doing? If not, some light reading
is in order :)

Troy.


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

Date: Tue, 11 Jul 2000 21:26:24 GMT
From: ynotssor@my-deja.com
Subject: Re: running system command as root from perl
Message-Id: <8kg3d9$8bl$1@nnrp1.deja.com>

In article <8kfepr$ndb$1@nnrp1.deja.com>,
  kmhanser@my-deja.com wrote:

> Okay, now I've got a killhttpd file:
> -r-sr-x---    1 root     www            60 Jul 11 11:24 killhttpd
> which looks like this:
> #!/bin/sh
> kill -USR1 `cat /usr/local/apache/logs/httpd.pid`
> However, when I run this program as www, it tells me:
> kill: (2476) - Not owner
> If I run as root, it works (obviously).

The user that is running the system script must be gid www, not uid.
You'll want to know the gid of your cgi script execution that is making
the system call.

> In article <brian-ya02408000R1007002308000001@news.panix.com>,
>   brian@smithrenaud.com (brian d foy) wrote:
>> In article <8ke1rg$nf7$1@nnrp1.deja.com>, ynotssor@my-deja.com
>> posted:
: The killhttpd program is a trivial script:
: #!/bin/sh
: kill -HUP `ps -aef | grep httpd | grep -v grep | awk '{print $2}'`
>>
>> that won't work for many reasons, and it's just dumb.
 ...


A response to brian@smithrenaud.com:
My, thanks so much for telling me that. Our Java developers, each of
whom has a separate Apache server running on priveleged port 80 for
their testing purposes, have been using exactly that script for about a
half year now, which directly the child processes as well as the parent
PID.

This is the first I've heard about its inadequacy.

Suppose you enumerate at least a few of the "many reasons", and I'll be
sure to rewrite the script so that they can continue their work without
all the failure that they've must have been encountering, but failed to
inform me of. (Look at me end my sentences in a preposition!)


-   tony


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 21:39:29 GMT
From: kmhanser@my-deja.com
Subject: Re: running system command as root from perl
Message-Id: <8kg46e$940$1@nnrp1.deja.com>

The www user (which is the account that cgi scripts are running as) is
set to have its primary group as www...

In article <8kg3d9$8bl$1@nnrp1.deja.com>,
  ynotssor@my-deja.com wrote:
> In article <8kfepr$ndb$1@nnrp1.deja.com>,
>   kmhanser@my-deja.com wrote:
>
> > Okay, now I've got a killhttpd file:
> > -r-sr-x---    1 root     www            60 Jul 11 11:24 killhttpd
> > which looks like this:
> > #!/bin/sh
> > kill -USR1 `cat /usr/local/apache/logs/httpd.pid`
> > However, when I run this program as www, it tells me:
> > kill: (2476) - Not owner
> > If I run as root, it works (obviously).
>
> The user that is running the system script must be gid www, not uid.
> You'll want to know the gid of your cgi script execution that is
making
> the system call.
>
> > In article <brian-ya02408000R1007002308000001@news.panix.com>,
> >   brian@smithrenaud.com (brian d foy) wrote:
> >> In article <8ke1rg$nf7$1@nnrp1.deja.com>, ynotssor@my-deja.com
> >> posted:
> : The killhttpd program is a trivial script:
> : #!/bin/sh
> : kill -HUP `ps -aef | grep httpd | grep -v grep | awk '{print $2}'`
> >>
> >> that won't work for many reasons, and it's just dumb.
> ...
>
> A response to brian@smithrenaud.com:
> My, thanks so much for telling me that. Our Java developers, each of
> whom has a separate Apache server running on priveleged port 80 for
> their testing purposes, have been using exactly that script for about
a
> half year now, which directly the child processes as well as the
parent
> PID.
>
> This is the first I've heard about its inadequacy.
>
> Suppose you enumerate at least a few of the "many reasons", and I'll
be
> sure to rewrite the script so that they can continue their work
without
> all the failure that they've must have been encountering, but failed
to
> inform me of. (Look at me end my sentences in a preposition!)
>
> -   tony
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 11 Jul 2000 17:54:18 -0400
From: brian@smithrenaud.com (brian d foy)
Subject: Re: running system command as root from perl
Message-Id: <brian-ya02408000R1107001754180001@news.panix.com>

In article <8kg3d9$8bl$1@nnrp1.deja.com>, ynotssor@my-deja.com posted:

> In article <8kfepr$ndb$1@nnrp1.deja.com>,
>   kmhanser@my-deja.com wrote:


> A response to brian@smithrenaud.com:
> My, thanks so much for telling me that. Our Java developers, each of
> whom has a separate Apache server running on priveleged port 80 for
> their testing purposes, have been using exactly that script for about a
> half year now, 

use is no endorsement.  lots of people use bad stuff.  use does not
mean that anything is good.

> which directly the child processes as well as the parent
> PID.

you shouldn't have to deal with the child processes at all.

> This is the first I've heard about its inadequacy.

it's in the apache docs.  *shrug*  don't complain to me if you
need to run six different processes when there is something
much simpler and documented.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Mongers <URL:http://www.perl.org/>


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

Date: Tue, 11 Jul 2000 14:54:34 -0600
From: TT <tjturner@chpc.utah.edu>
Subject: scripting question
Message-Id: <396B898A.3014714F@chpc.utah.edu>


Hello;

Please help me get the elseif statement at the bottom which I commented
to work.

I'm getting the error tailing the apache log file:

disconnect(DBI::db=HASH(0x81d5c90)) invalidates 1 active statement.
Either destroy statement handles or call finish on them before
disconnecting. at /usr/local/apache/cgi-bin/piinfo.pl line 68.

All I want is that if no value exists in my database, the elseif of user
not found html/cgi web content would be returned.

Thank you for your time.


#!/usr/bin/perl

use CGI qw(param);
use DBI;

$usrvar = param("Query");

$userfile='/usr/local/apache/cgi-bin/usernames';

open(USERS, "<$userfile") or die "could not open file userfile";

$dbh = DBI->connect("dbi:Pg:dbname=newqbank", "postgres");

if ( !defined $dbh ) {
die "Cannot connect to database!\n";
}

if ($usrvar ne undef) {
$sth = $dbh->prepare("select username, realname from userinfo where
username='$usrvar'");
$sth->execute;

while(@row = $sth->fetchrow()) {
    if (@row ne undef) {
 ($realname, $realname2, $username, $username2)=(split, @row);

#{ print USERS "@row\n"; }

print "Content-type: text/html

<html>
<title>Account Allocation Form</title>

<body bgcolor=#ffffff text=#000000 link=#3333ff vlink=#ff3333
alink=#33ff33>
<td align=left><font face=\"Arial,Helvetica\" color=black><b>
<table>
<tr>  <font size=+1><b>QBank PI INFO:</b><br></font>
<td align=left><font
face=\"Arial,Helvetica\"><B>USERID:</B>&nbsp;&nbsp;$realname&nbsp;</font></td>

<td align=left><font
face=\"Arial,Helvetica\">&nbsp;&nbsp;&nbsp;</font></td>
<td align=left><font
face=\"Arial,Helvetica\"><B>NAME:</B>&nbsp;&nbsp;&nbsp;$realname2&nbsp;</font></td>

<td align=left><font
face=\"Arial,Helvetica\">&nbsp;&nbsp;&nbsp;</font></td>
<td align=left><font
face=\"Arial,Helvetica\"><B>SU's:</B>&nbsp;&nbsp;test&nbsp;</font></td>
<td align=left><font
face=\"Arial,Helvetica\">&nbsp;&nbsp;&nbsp;</font></td>
<td align=left><font
face=\"Arial,Helvetica\"><B>CONSUMED:</B></font></td>
<td align=left><font
face=\"Arial,Helvetica\">&nbsp;&nbsp;test&nbsp;</font></td>
<td align=left><font
face=\"Arial,Helvetica\"><B>PERCENTAGE:</B></font></td>
<td align=left><font
face=\"Arial,Helvetica\">&nbsp;&nbsp;test&nbsp;</font></td>
</table>
</body>
</html>";
}

# Can't get this  else if to return

elsif ($sth->rows == 0) {

print "Content-type: text/html

<html>
<title>CHPC Account Allocation Form</title>

<body bgcolor=#ffffff text=#000000 link=#3333ff vlink=#ff3333
alink=#33ff33>

<h2>This PI wasn't found</h2>

</body>
</html>";

}

$dbh->disconnect;

}
}
close(USERS);




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

Date: 11 Jul 2000 21:20:27 GMT
From: newsposter@cthulhu.demon.nl
Subject: Re: scripting question
Message-Id: <8kg32r$473$1@internal-news.uu.net>

TT <tjturner@chpc.utah.edu> wrote:

> Hello;

> Please help me get the elseif statement at the bottom which I commented
> to work.

> I'm getting the error tailing the apache log file:

> disconnect(DBI::db=HASH(0x81d5c90)) invalidates 1 active statement.
> Either destroy statement handles or call finish on them before
> disconnecting. at /usr/local/apache/cgi-bin/piinfo.pl line 68.

structure of your code:

---------------------------------------
while(@row = $sth->fetchrow()) {
    if (@row ne undef) {
    }
    elsif ($sth->rows == 0) {
    }

    $dbh->disconnect;
}
---------------------------------------
This code doesn't make sense to me. The $sth->rows can only be used
_after_ you fetched all rows, so it should be outside the while loop.

   The '@row ne undef' probably does not do what you think/want it to
do. @row gets evaluated to number of elements in the list, and then
do a string compare with undef???

until youy fetched all rows, you have a cursor open. Disconnecting
from the database then displays an error. You can close the statement
by calling 'finish' in it.

If I understand your question correctly you want to do something
like this:

---------------------------------------
while(@row = $sth->fetchrow()) {
    # process row
}
if ($sth->rows == 0) {
    # handle 'no rows'
}

$sth->finish ();
$dbh->disconnect;
---------------------------------------




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

Date: Tue, 11 Jul 2000 11:47:08 -0700
From: Stephen Carpenter <stephen_carpenter@hp.com>
Subject: Re: slow learner needs help with splice ()
Message-Id: <396B6BAC.DF6E7501@hp.com>

OK,

@x = ("aa","bb","cc","dd");
($x, $y, $z) = splice (@x, 0, 3);

works fine.

Stephen Carpenter wrote:

> Hello,
>
>     I am using ActiveState Perl build 522 on Windows 2000. Anyway, I am
> slowly learning Perl but I am having problems with the splice function.
> My book, Programming Perl 2nd Edition, says on page 198 about pop that I
> should use splice to pop multiple elements of an array. On page 219 I
> read about splice, but I guess I am too slow on the uptake. What I am
> trying to do is something like this:
>
> @x = "aa","bb","cc","dd";
> $x, $y, $z = splice (@x, 0, 3);
>
> to get the first three elements. The book says that splice returns the
> elements removed from the array, but I just can't seem to figure it out.
>
> StephenC.
> PS. I don't know C either, so please don't tell me it is just like C.



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

Date: Tue, 11 Jul 2000 21:09:55 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: split NONSENSE
Message-Id: <m5smmskof5phij1ps7l9c7feijvaliomf3@4ax.com>

Abigail wrote:

>*shrug*. Supposed "split /:/, "", -1" returned a list of a single empty
>string. Then someone would ask "there's no way to have split return an
>empty list with -1 as a third parameter".

Probably.

It just shows that you can't get DWIM for every instance of M.

-- 
	Bart.


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

Date: 11 Jul 2000 19:11:31 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: String length?
Message-Id: <8kfrh3$1h6$1@news.NERO.NET>

In article <slrn8mlkp6.j41.sholden@pgrad.cs.usyd.edu.au>,
Sam Holden <sholden@cs.usyd.edu.au> wrote:
>>I wasn't trying to write something long. I was presenting another
>>ludicrous way of counting string lengths. It wasn't supposed to be
>>used.
>
>But if it doesn't work then it isn't a way to find the length of a string.

It would take two minor fixes to make it work. It wouldn't always give
the right answer, but the fun is in thinking about alternate ways --
unless we've abandoned the TIMTOWTDI philosophy.

>This is comp.lang.perl.misc... 

I know what group this is.

>However, if the method doesn't actually work it is less
>funny, and just indicates the author didn't think about the perl part very
>well.

Excuse the hell out of me for making a mistake and then apologizing for
it.



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

Date: Tue, 11 Jul 2000 15:58:10 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: String length?
Message-Id: <396B8A62.D01BDFF8@rac.ray.com>

Ala Qumsieh wrote:
> 
> Everybody so far has given you some kind of answer (sarcastic or
> not). Don't listen to them! String length is a function of Heisenberg's
> principle:
> 
>         sub heisenbergs_length {
>                 my $s = shift;
> 
>                 my $length = 0;
> 
>                 $_ >= 0.5 && $length++ while $_ = rand > 0.1;
> 
>                 $length;
>         }
> 
> Note that the length changes as you are trying to measure it, just as
> Heisenberg predicted.
> 


#!/opt/perl5/bin/perl -w
use strict;

my $len = schroedingers_length("Heisenberg might have slept here");
print "Length is $len\n";
exit(0);

sub schroedingers_length
{
  my $str = shift;
  # get the putative length
  my $cat = length($str);
  srand(times() ^ ($$ + ($$ << 15)));
  my $cesium_atom = rand();     # pick an individual atom
  my $decay = sprintf("%1.0f",$cesium_atom); # has it decayed?
  return ($cat * $decay);	# probability wave collapses here
}
  


-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: Tue, 11 Jul 2000 05:21:09 -0400
From: EPROM <eprom007@hotmail.com>
Subject: Re: stupid perl question
Message-Id: <396AE705.FD58FFBF@hotmail.com>

Thank you, for being one of the few who can give a clear anwser.

without the "oh go read the man page"...
sheesh...im not a Perl programmer, nor do I intend to be in the near
future.
this is for a project at work.

and again, Thanks :)

Leo Schalkwyk wrote:

>
> well you seem to have ls aliased to 'ls -l', but the simplest
> ls behaviour is easy to get with a glob:
>
> perl -le'$,="\n";print<*>'
>



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3626
**************************************


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