[29241] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 485 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 5 18:10:13 2007

Date: Tue, 5 Jun 2007 15:09:07 -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           Tue, 5 Jun 2007     Volume: 11 Number: 485

Today's topics:
    Re: Can't modify constant item in scalar assignment <glennj@ncf.ca>
    Re: Help with Perl operators Please! <scrarymary1@hotmail.com>
    Re: Help with Perl operators Please! <scrarymary1@hotmail.com>
    Re: Help with Perl operators Please! <scrarymary1@hotmail.com>
    Re: Help With Placeholders <xicheng@gmail.com>
    Re: Help With Placeholders <bart.lateur@pandora.be>
    Re: How to erase Hex value 13 from string? <bart.lateur@pandora.be>
    Re: How to erase Hex value 13 from string? <noreply@gunnar.cc>
        How to list all the nested modules <hslee911@yahoo.com>
    Re: How to list all the nested modules <mritty@gmail.com>
    Re: How to list all the nested modules  usenet@DavidFilmer.com
    Re: merging two files <glex_no-spam@qwest-spam-no.invalid>
    Re: merging two files <glex_no-spam@qwest-spam-no.invalid>
    Re: Need suggestions on a good locking module <waveright@gmail.com>
    Re: Need suggestions on a good locking module <bart.lateur@pandora.be>
    Re: Re-entrant code ??? <tyjbxx@yahoo.com>
    Re: Re-entrant code ??? <mritty@gmail.com>
        simple regex <regis44@gmail.com>
    Re: simple regex <mritty@gmail.com>
    Re: Spawning other processes but continue script <shmh@bigpond.net.au>
        system call  hendedav@gmail.com
    Re: system call <jgibson@mail.arc.nasa.gov>
    Re: system call  hendedav@gmail.com
    Re: system call  hendedav@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 5 Jun 2007 15:43:04 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Can't modify constant item in scalar assignment
Message-Id: <slrnf6b149.gfv.glennj@smeagol.ncf.ca>

At 2007-06-04 11:21PM, "emrefan" wrote:
>  On Jun 5, 10:30 am, Uri Guttman <u...@stemsystems.com> wrote:
> > >>>>> "e" == emrefan  <dksle...@hotmail.com> writes:
> >   e> fileLastModTm = localtime( (stat shift)[9] );
> >   e> $fileLastModTm[4]++;  # month no. was zero-based, change that
> >   e> $fileLastModTm[5] += 1900; # year no. was 1900-based, change that
> >   e> fileLastModTm[ 5, 4, 3 ];  # spit it out, in yyyymmdd format
[...]
>  Ah, I looked at the thing closely just now and boy what blunder did I
>  make! So a @ was missing from the 1st line and "print $" was missing
>  from the last line. 

Note that this command:
    print $fileLastModTm[ 5, 4, 3 ];
is not going to:
    # spit it out, in yyyymmdd format

Array slices (the "[5,4,3]" construct) imply you want multiple items, so
you have to reference the variable name with "@".  You would want:
    printf "%4d%02d%02d", @fileLastModTm[ 5, 4, 3 ];

However, you can avoid the month/year adjustments altogether with:
    use POSIX 'strftime';
    my $fileModDate = strftime('%Y%m%d', localtime( (stat shift)[9] ));

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


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

Date: Tue, 05 Jun 2007 15:33:18 -0600
From: scrarymary <scrarymary1@hotmail.com>
Subject: Re: Help with Perl operators Please!
Message-Id: <sjlb635hlemlls4gad2ql3l4fr5b1d1shi@4ax.com>

On Tue, 5 Jun 2007 01:33:37 +1000, "Sisyphus"
<sisyphus1@nomail.afraid.org> wrote:

>Cheers,
>Rob 

Thank you



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

Date: Tue, 05 Jun 2007 15:33:59 -0600
From: scrarymary <scrarymary1@hotmail.com>
Subject: Re: Help with Perl operators Please!
Message-Id: <4llb63dgqgdaojat28rm1rb44177tcjuh0@4ax.com>

On Mon, 04 Jun 2007 16:45:10 +0100, Ian Wilson
<scobloke2@infotop.co.uk> wrote:

thanks


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

Date: Tue, 05 Jun 2007 15:35:16 -0600
From: scrarymary <scrarymary1@hotmail.com>
Subject: Re: Help with Perl operators Please!
Message-Id: <emlb639mtrgt12onhkoiuier6oo8t93bq7@4ax.com>

On Mon, 04 Jun 2007 10:50:48 -0500, "J. Gleixner"
<glex_no-spam@qwest-spam-no.invalid> wrote:

>Instead of asking what will happen, why not try it and see for yourself?
Normally I would but had trouble getting things to run

Thanks for your help



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

Date: Tue, 05 Jun 2007 16:04:55 -0000
From:  Xicheng Jia <xicheng@gmail.com>
Subject: Re: Help With Placeholders
Message-Id: <1181059495.554631.72620@p47g2000hsd.googlegroups.com>

On Jun 4, 8:14 pm, PerlGoon <mburg...@gmail.com> wrote:
> This question pertains to using DBI with a MySQL database.....
>
> I use placeholders for all my queries (mainly for security). The
> problem I have is that I need to be able to print the actual queries
> my code runs into a log.... with the placeholders replaced.
>
> For example, consider the following:
>
> my $id = "example";
> my $sql = "UPDATE Customers SET ID=?";
> my $query = $db->prepare($sql);
> $query->execute($id);
>
> How do I print the ACTUAL query that was run into a log file.... with
> the placeholders replaced???
>
> For example, when I do the following:
>
> print $sql;
>
> It prints:
>
> UPDATE Customers SET ID=?
>
> When I need it to print:
>
> UPDATE Customers SET ID='example'
>
> I know that I could replace the placeholders myself... but then
> again... I need to log the ACTUAL query that was just executed... or
> attempted to be executed.

How about this:

    my $log_sql = $sql;
    $log_sql =~ s{\?}{'$_'} for @values;
    print $log_sql;

the array @values keeps all the binding values to the placeholders,
for your case, it's

    my @values = qw($id);

you can pack this into a subroutine, i.e.

sub printSQL {
    my $sql = shift;
    print $sql and return if not @_;
    $sql =~ s{\?}{'$_'} for @_;
    print index($sql, '?') > 0 ? "need more binding values\n" : $sql;
}

(untested)

Regards,
Xicheng



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

Date: Tue, 05 Jun 2007 21:38:57 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Help With Placeholders
Message-Id: <jplb63h8khd4iiq6fuap8qeu07il8ihr6u@4ax.com>

PerlGoon wrote:

> The
>problem I have is that I need to be able to print the actual queries
>my code runs into a log.... with the placeholders replaced.
>
>For example, consider the following:
>
>my $id = "example";
>my $sql = "UPDATE Customers SET ID=?";
>my $query = $db->prepare($sql);
>$query->execute($id);
>
>How do I print the ACTUAL query that was run into a log file.... with
>the placeholders replaced???

You can replace each placeholder in the SQL statement with a value
calculated as $dbh->quote($_) for the next bind value.

You might be able to do that by overriding execute and putting the
logging in that method, though I bet it will not be easy: DBI is a very
hard module to subclass.

-- 
	Bart.


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

Date: Tue, 05 Jun 2007 19:58:14 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: How to erase Hex value 13 from string?
Message-Id: <b0gb631d6voff5579ijc71cfh4a5bl712f@4ax.com>

Gunnar Hjalmarsson wrote:

>Taomica wrote:
>> How to erase Hex value 13 from string?
>> 
>> Perl line :                    $b =~ tr/\013//;
>> dont work?!
>
>You missed the /d modifier.

You missed the fact that \013 is in octal, not in hex.

And the OP may just have missed that hex "13" is not decimal 13, which
seems like a far more likely candidate to want to delete.

-- 
	Bart.


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

Date: Tue, 05 Jun 2007 22:20:08 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to erase Hex value 13 from string?
Message-Id: <5clv0qF3183faU1@mid.individual.net>

Bart Lateur wrote:
> Gunnar Hjalmarsson wrote:
>> Taomica wrote:
>>> How to erase Hex value 13 from string?
>>>
>>> Perl line :                    $b =~ tr/\013//;
>>> dont work?!
>>
>> You missed the /d modifier.
> 
> You missed the fact that \013 is in octal, not in hex.

Since you say that *I* missed, I have to ask: Is there a requirement to 
cover the whole problem when you try to help here?

I didn't even consider the SEARCHLIST, but I know that you need the /d 
modifier to erase characters with the tr() operator, and I chose to call 
the OP:s attention to that. Shouldn't I have done so?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Tue, 05 Jun 2007 13:40:15 -0700
From:  James <hslee911@yahoo.com>
Subject: How to list all the nested modules
Message-Id: <1181076015.068256.17980@n4g2000hsb.googlegroups.com>

How to list all the nested modules,
similar to dependency in C-compiler (gcc -M)?

For example,

use Net::SSH::Perl::Packet;
use Net::SSH::Perl::Buffer;
use Net::SSH::Perl::Config;
use Net::SSH::Perl::Constants qw( :protocol :compat :hosts );
use Net::SSH::Perl::Cipher;
use Net::SSH::Perl::Util qw( :hosts _read_yes_or_no );
use IO::Socket;
use IO::Select;
use Socket;
use Fcntl;
use Symbol;
use Errno qw(EAGAIN EWOULDBLOCK);
use Carp qw(croak);
use Sys::Hostname;


TIA
James



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

Date: Tue, 05 Jun 2007 20:54:36 -0000
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: How to list all the nested modules
Message-Id: <1181076876.593077.325850@o5g2000hsb.googlegroups.com>

On Jun 5, 4:40 pm, James <hslee...@yahoo.com> wrote:
> How to list all the nested modules,
> similar to dependency in C-compiler (gcc -M)?
>
> For example,
>
> use Net::SSH::Perl::Packet;
> use Net::SSH::Perl::Buffer;
> use Net::SSH::Perl::Config;
> use Net::SSH::Perl::Constants qw( :protocol :compat :hosts );
> use Net::SSH::Perl::Cipher;
> use Net::SSH::Perl::Util qw( :hosts _read_yes_or_no );
> use IO::Socket;
> use IO::Select;
> use Socket;
> use Fcntl;
> use Symbol;
> use Errno qw(EAGAIN EWOULDBLOCK);
> use Carp qw(croak);
> use Sys::Hostname;

Not quite sure what you're going for, but maybe you want the keys of
the %INC hash?

$ perl -MLWP::Simple -le'
for (sort keys %INC) {
   s!/!::!g;
   s!\.pm$!!;
   print;
}
'
Carp
Exporter
Exporter::Heavy
HTTP::Status
LWP::Simple
strict
vars
warnings
warnings::register

Paul Lalli



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

Date: Tue, 05 Jun 2007 20:55:19 -0000
From:  usenet@DavidFilmer.com
Subject: Re: How to list all the nested modules
Message-Id: <1181076919.773328.306010@z28g2000prd.googlegroups.com>

On Jun 5, 1:40 pm, James <hslee...@yahoo.com> wrote:
> How to list all the nested modules,

At any time in a program you may print the contents of %INC, which
will tell you what modules are loaded (you may prefer to print it
using Dumper).

If you want to know every module ever loaded, use an end block, such
as:

END {
   print Dumper \%INC;

}

If you wish to know how much time your program spent inside of each
method of each module:

perl -d:Profile whatever.pl


--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



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

Date: Tue, 05 Jun 2007 12:28:44 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: merging two files
Message-Id: <46659d4c$0$495$815e3792@news.qwest.net>

) = split /:/, $line;Vahid wrote:
> Hi all,
> Is it possible to parse two colon delimited files and merge one field
> from one of the files with the other file? For example if I want to
> merge the second field (b) of the first file with the contents of
> a:b:c:d with the third field of the second file with the contents of
> e:f:g:h, I would get e:f:b:h. I came up with the following but don't
> know where to add the parser for the second file?

First, determine what column is the 'key' for each file.

Read file 1, 'split' each line and create a hash with the value of the 
'b' column and the key being the common column in both files.

While reading file 2, 'split' the line. Based on the 'key' column,
use the value from file1 for the 'g' column, and write it to your
new file.


use strict;
use warnings;
> 
> sub mkShadow() {
>         open (SHADOWfh, "<$SHADOW") || die "Can not open the file:
> $SHADOW. $!\n";
>         open (PASSWDfh, "<$PASSWD") || die "Can not open the file:
> $PASSWD. $!\n";
>         open (XSHADOWfh, ">$XSHADOW") || die "Can not open the file:
> $XSHADOW. $!\n";
> 
>         @lines = <SHADOWfh> ;
> ###   @linesX = <XSHADOWfh> # this is what I want
>         foreach $line (@lines) {

Typically, you want to avoid reading the entire file into an array.
Instead, read the file, line by line, storing what's needed from
those lines.

e.g.
	while( my $line = <SHADOWfh> )

or

	open( my $shadow, '<', $SHADOW ) or die "...";
	while( my $line  = $shadow )

>         ## what goes here?
>         # Skip comments
>         next if (m/^#/);
>         # Skip blank lines
>         next if (m/^\s*$/);
>         ($username,$pass,$lastchange) = split /:/, $line;

my( $username,$pass,$lastchange) = (split /:/, $line)[0,1,2];

>         ## what goes here?
>         $x_lastupdate = ($lastchange*86400);
Who knows, you didn't mention anything about this column.
>         #
>         print $XSHADOWfh ("username: %s password: %s lastupdate: %d
> \n", \
>                 $username,$pass,$x_lastupdate) ;
>         } # for each
>         close $SHADOWfh;
>         close $XSHADOWfh;
>         close $PASSWDfh;
>         @args = ("pwdck", "-y", "ALL");
>         system(@args) == 0 or warn "System @args failed: $?";
> }
> 
> Thank you very much,
> 


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

Date: Tue, 05 Jun 2007 12:31:02 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: merging two files
Message-Id: <46659dd6$0$495$815e3792@news.qwest.net>

J. Gleixner wrote:
> ) = split /:/, $line;Vahid wrote:
Sorry.. about that. bad paste on my part.

 >>Vahid wrote
>> Hi all,


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

Date: Tue, 05 Jun 2007 20:39:09 -0000
From:  trwww <waveright@gmail.com>
Subject: Re: Need suggestions on a good locking module
Message-Id: <1181075949.967449.258670@w5g2000hsg.googlegroups.com>

On Jun 5, 4:23 am, Heinrich.Mis...@univie.ac.at (Heinrich Mislik)
wrote:
> In article <MP6dndxNyasrifnbnZ2dnUVZ_v-tn...@giganews.com>, ignoramus27...@NOSPAM.27175.invalid says...
>
> >I have a script that I want to run, but only one instance. So I want
> >to set up crontab to start it every minute, but if it is already
> >running, I would exit.
>
> Look at Proc::PID::File

Theres also File::Pid. A (very) quick glance at the source for both
leads me to believe File::Pid is cleaner.

Looks like Proc::PID::File isnt portable (uses ps in backticks).
File::Pid uses perl's kill().

Anyone got any opinions on which is better?

Todd W.



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

Date: Tue, 05 Jun 2007 21:25:25 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Need suggestions on a good locking module
Message-Id: <rvkb63pmruoc6slm3s984g3kia5t8inhro@4ax.com>

desas2@gmail.com wrote:

>At the start of the program create a file if it does not exist and at
>the end delete a file. If the file exists, then exit program.

And what if the program crashes or gets interrupted? That way, the
lockfile would never be deleted.

And you have a race condition, between testing if the file exists, and
actually creating it (unless you're openign the file with the O_EXCL
flag (from Fcntl), which somehow I doubt.) (see
http://bama.ua.edu/cgi-bin/man-cgi?open+2)

-- 
	Bart.


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

Date: Tue, 05 Jun 2007 11:15:19 -0700
From:  tyjb <tyjbxx@yahoo.com>
Subject: Re: Re-entrant code ???
Message-Id: <1181067319.242455.211290@q75g2000hsh.googlegroups.com>

On Jun 5, 10:07 am, Paul Lalli <mri...@gmail.com> wrote:
> On Jun 5, 8:58 am, tyjb <tyj...@yahoo.com> wrote:
>
> > I'm new to Windows perl and am recreating a menuing system that we
> > have on Unix, perl calling perl using the do command.  The menus
> > present options to users with some options going to other menus.  When
> > I execute one of the options, not another menu, I use "return" to
> > return to the calling menu/program.  When I do, all numeric inputs
> > from the user are ignored.  The only valid input is an "e" which exits
> > the menu.  Any idea what's happening?  Below is the code that returns
> > the program to the calling program.
>
> > if ($length == 0) {
> > print "Job $job currently has no output to display\n";
> >         sleep 3;
> >         return; }
>
> Please post a short BUT COMPLETE program that demonstrates what the
> heck you're talking about.
>
> This and other good advice can be found in the Posting Guidelines for
> this group, posted here twice weekly.
>
> Paul Lalli

Here's how the parent calls the child:

chomp($input = <STDIN>);									if ($input eq "1") {
	   $load_cmd = "perl -w \\\\tlrntfs1\\IT_Common\\PMT\\jobs\\ojob.pl";
	   system("$load_cmd");

Here's the child returning to the parent:

while (true) {
         system(($^O eq 'MSWin32') ? 'cls' : 'clear');						print
"********************************************************\n";
	print "**************** DISPLAY ACTIVITY **********************\n";
	print "*********( Auto Cycles Every 5 seconds )****************\n";
	print "********************************************************\n";
	print " \n";
	($sec, $min, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek,
$dayOfYear, undef) = localtime();
	$mins  = sprintf "%02u", $min;
	$hours = sprintf "%02u", $hour;
	$secs  = sprintf "%02u", $sec;
	$string = "Current Date & Time: $weekDays[$dayOfWeek] $months[$month]
$dayOfMonth, $year   $hours:$mins:$secs Central\n";
	print "$string\n";
	print " \n";
	@array = glob("*");
	foreach $filex (@array)									{
	open(INFO, $filex);									@lines = <INFO>;
close(INFO);										print @lines;									}
	print " \n";
	print " \n";
	print "************>>>>> to quit, do a Control / C\n";
	$SIG{INT} = sub{&create_break};
	if ($a_ok == $nah) {
		$input = "";
		return; }
	sleep 5
	}

         sub create_break {
	  $a_ok = $nah; }



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

Date: Tue, 05 Jun 2007 12:29:49 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Re-entrant code ???
Message-Id: <1181071789.060450.114460@q66g2000hsg.googlegroups.com>

On Jun 5, 2:15 pm, tyjb <tyj...@yahoo.com> wrote:
> On Jun 5, 10:07 am, Paul Lalli <mri...@gmail.com> wrote:

> > On Jun 5, 8:58 am, tyjb <tyj...@yahoo.com> wrote:
>
> > > I'm new to Windows perl and am recreating a menuing system that we
> > > have on Unix, perl calling perl using the do command.  The menus
> > > present options to users with some options going to other menus.  When
> > > I execute one of the options, not another menu, I use "return" to
> > > return to the calling menu/program.  When I do, all numeric inputs
> > > from the user are ignored.  The only valid input is an "e" which exits
> > > the menu.  Any idea what's happening?  Below is the code that returns
> > > the program to the calling program.
>
> > > if ($length == 0) {
> > > print "Job $job currently has no output to display\n";
> > >         sleep 3;
> > >         return; }
>
> > Please post a short BUT COMPLETE program that demonstrates what the
> > heck you're talking about.
>

> Here's how the parent calls the child:

Which part of "complete" confused you?

Nothing in anything you posted shows how the child is supposedly
passing input back to the parent.  Nothing in anything you posted
shows the supposed do{} command that's calling a child.  Nothing in
anything you posted is reading data from the user.

Pare your problem down to the SHORTEST COMPLETE script that still
exhibits the problem.  And then post that.

It's also fairly apparent from the code you posted that you're using
neither strict nor warnings.  Start using both.  They find 95% of the
errors you're likely to make.

Paul Lalli



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

Date: Tue, 05 Jun 2007 09:33:17 -0700
From:  r3gis <regis44@gmail.com>
Subject: simple regex
Message-Id: <1181061197.849235.255800@k79g2000hse.googlegroups.com>

Hi
I am trying to extract all  URLs ending with php or cgi or pl from one
website with the following code :
    foreach $judge( $res->content=~m#((http://[a-z-\/\.~]+\.(php|cgi|
pl)))#g)
                {
                        print $judge,"\n";
                }
But for some reason I get redundant results :

http://www.kanazawa-gu.ac.jp/~hayashiy/cgi-bin/log/env.cgi
cgi
http://www.bsnoop.de/cgi-bin/jenv.cgi
cgi

etc.

Could someone explain to me why the file extension is present in this
result set . What am I doing wrong ?



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

Date: Tue, 05 Jun 2007 09:38:07 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: simple regex
Message-Id: <1181061487.028913.191040@n4g2000hsb.googlegroups.com>

On Jun 5, 12:33 pm, r3gis <regi...@gmail.com> wrote:
> Hi
> I am trying to extract all  URLs ending with php or cgi or pl from one
> website with the following code :
>     foreach $judge( $res->content=~m#((http://[a-z-\/\.~]+\.(php|cgi|
> pl)))#g)
>                 {
>                         print $judge,"\n";
>                 }
> But for some reason I get redundant results :
>
> http://www.kanazawa-gu.ac.jp/~hayashiy/cgi-bin/log/env.cgi
> cgihttp://www.bsnoop.de/cgi-bin/jenv.cgi
> cgi
>
> etc.
>
> Could someone explain to me why the file extension is present in this
> result set . What am I doing wrong ?

You have multiple capturing parentheses in your pattern match.  A
pattern match in list context (such as that imposed by the foreach
loop) returns a list of ALL captured parentheses.

Change the ones you don't want to capture to be noncapturing, by
adding a ?: right after the (

See also:
perldoc perlre
perldoc perlretut
perldoc perlreref

Paul Lalli



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

Date: Tue, 05 Jun 2007 15:11:28 GMT
From: "SimonH" <shmh@bigpond.net.au>
Subject: Re: Spawning other processes but continue script
Message-Id: <A2f9i.9192$wH4.2476@news-server.bigpond.net.au>

Thanks guys.....Ill do some more reading....still a newbie big time...Thanks 
for all your help.

"Joe Smith" <joe@inwap.com> wrote in message 
news:XYGdnZA3XZxlgPjbnZ2dnUVZ_jednZ2d@comcast.com...
> SimonH wrote:
>>      print `notepad`;
>
> Why do you want to print 0?  That is, why are backticks (``) being used?
>
> It looks like the author does not know the difference between
>
> $captured_output_from_program = `notepad`;
>
> and
>
> $error_code_exit_status = system 'notepad';
>
> C:\> perldoc -q "output of a command"
>
> -Joe 




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

Date: Tue, 05 Jun 2007 11:03:14 -0700
From:  hendedav@gmail.com
Subject: system call
Message-Id: <1181066594.594834.6630@g4g2000hsf.googlegroups.com>

Gang,

     I am using a cgi to call a pl script and then pass xml back to
the web browser (code listed below).  The problem I am having is that
the code in the cgi executes promptly and as it should, but the return
values, for some reason, don't get sent to the browser until the pl
script is completed.  Currently the pl script accepts two parameters
(but does nothing with the first one currently) and just uses a while
loop that counts to the 2nd passed value.  If anyone can help with
this (or knows a better way to get the pid, please let me know.

Dave



$_ = param('runnow');   # passed variable value
if (system("./backup.pl \"$_\" 30 \&") == 0) {
   $_ = `ps aux|grep "backup.pl $_" 2>&1`;     # finds the pid of the
pl
   my ($pid) = /(\d{3,})/;    # isolates the pid only
   chomp($pid);
   my @info = stat("/tmp/buj$pid");   # this file is created by the pl
script

   print "Content-type: text/xml\n\n\n";
   print "<info pid=\"". $pid ."\" date=\"". scalar(localtime) ."\" /
>";
}



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

Date: Tue, 05 Jun 2007 11:57:43 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: system call
Message-Id: <050620071157438193%jgibson@mail.arc.nasa.gov>

In article <1181066594.594834.6630@g4g2000hsf.googlegroups.com>,
<hendedav@gmail.com> wrote:

> Gang,
> 
>      I am using a cgi to call a pl script and then pass xml back to
> the web browser (code listed below).  The problem I am having is that
> the code in the cgi executes promptly and as it should, but the return
> values, for some reason, don't get sent to the browser until the pl
> script is completed.  Currently the pl script accepts two parameters
> (but does nothing with the first one currently) and just uses a while
> loop that counts to the 2nd passed value.  If anyone can help with
> this (or knows a better way to get the pid, please let me know.
> 
> Dave
> 
> 
> 
> $_ = param('runnow');   # passed variable value
> if (system("./backup.pl \"$_\" 30 \&") == 0) {
>    $_ = `ps aux|grep "backup.pl $_" 2>&1`;     # finds the pid of the
> pl
>    my ($pid) = /(\d{3,})/;    # isolates the pid only
>    chomp($pid);
Unnecessary, as $pid will contain only decimal digits.

>    my @info = stat("/tmp/buj$pid");   # this file is created by the pl
> script
> 
>    print "Content-type: text/xml\n\n\n";
>    print "<info pid=\"". $pid ."\" date=\"". scalar(localtime) ."\" /
> >";
> }
> 

Where is the while loop you described? Are you describing one program
and posting another?

In any case, what happens after your Perl program emits output is up to
your web server and the client's browser. It is not under Perl's
control. However, you can maybe help things to move along more quickly
by flushing the output. See 'perldoc -q flush' for details.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Tue, 05 Jun 2007 12:11:25 -0700
From:  hendedav@gmail.com
Subject: Re: system call
Message-Id: <1181070685.255100.309640@k79g2000hse.googlegroups.com>

On Jun 5, 2:57 pm, Jim Gibson <jgib...@mail.arc.nasa.gov> wrote:
> In article <1181066594.594834.6...@g4g2000hsf.googlegroups.com>,
>
>
>
> <hende...@gmail.com> wrote:
> > Gang,
>
> >      I am using a cgi to call a pl script and then pass xml back to
> > the web browser (code listed below).  The problem I am having is that
> > the code in the cgi executes promptly and as it should, but the return
> > values, for some reason, don't get sent to the browser until the pl
> > script is completed.  Currently the pl script accepts two parameters
> > (but does nothing with the first one currently) and just uses a while
> > loop that counts to the 2nd passed value.  If anyone can help with
> > this (or knows a better way to get the pid, please let me know.
>
> > Dave
>
> > $_ = param('runnow');   # passed variable value
> > if (system("./backup.pl \"$_\" 30 \&") == 0) {
> >    $_ = `ps aux|grep "backup.pl $_" 2>&1`;     # finds the pid of the
> > pl
> >    my ($pid) = /(\d{3,})/;    # isolates the pid only
> >    chomp($pid);
>
> Unnecessary, as $pid will contain only decimal digits.
>
> >    my @info = stat("/tmp/buj$pid");   # this file is created by the pl
> > script
>
> >    print "Content-type: text/xml\n\n\n";
> >    print "<info pid=\"". $pid ."\" date=\"". scalar(localtime) ."\" /
> > >";
> > }
>
> Where is the while loop you described? Are you describing one program
> and posting another?
>
> In any case, what happens after your Perl program emits output is up to
> your web server and the client's browser. It is not under Perl's
> control. However, you can maybe help things to move along more quickly
> by flushing the output. See 'perldoc -q flush' for details.
>
>  Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
>     ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
>                http://www.usenet.com


Thanks for the reply.  The while loop is stored in the pl file (listed
below).  But if perl sends the xml listed above and exists immediately
after, why would the browser not process it?  Since the system call
has an appended & at the end to indicate to run as a seperate process,
the browser shouldn't be waiting on perl to finish that additional
script call, right?



entire contents of the test.pl script:
----------------------------------------
#!/usr/bin/perl -w

my $test = $ARGV[0];
my $duration = $ARGV[1];

$_ = `ps aux|grep "test.pl $test" 2>&1`;
my ($pid) = /(\d{3,})/;
chomp($pid);
open(TMP, ">/tmp/buj$pid") || die "Can't create: $!\n";
close(TMP);

my $i=0;
while ($i<$duration) {
   sleep(1);
   $i++;
}
unlink "/tmp/buj$pid";          # erase the /tmp/bujPID file



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

Date: Tue, 05 Jun 2007 12:13:42 -0700
From:  hendedav@gmail.com
Subject: Re: system call
Message-Id: <1181070822.400483.242960@m36g2000hse.googlegroups.com>

The original section of code was from the cgi script that calls the
test.pl script.  Sorry for not specifying.

Dave



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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 485
**************************************


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