[28945] in Perl-Users-Digest
Perl-Users Digest, Issue: 189 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 3 00:10:10 2007
Date: Fri, 2 Mar 2007 21:09:04 -0800 (PST)
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, 2 Mar 2007 Volume: 11 Number: 189
Today's topics:
Re: Cool Free Offers <uri@stemsystems.com>
Re: display datestamp in HTML <paduille.4060.mumia.w+nospam@earthlink.net>
Re: display datestamp in HTML <glennj@ncf.ca>
Re: Error In DBI - Cannot execute multiple statements <hjp-usenet2@hjp.at>
Re: Error In DBI - Cannot execute multiple statements <mritty@gmail.com>
Re: FAQ 6.21 What's wrong with using grep in a void con <uri@stemsystems.com>
Re: Q on regex of LWP::Simple data <wahab-mail@gmx.de>
Re: Q on regex of LWP::Simple data <len@philpot.org>
Why 'No child processes' after a system() call danrumney@warpmail.net
Re: Why 'No child processes' after a system() call <ddunham@redwood.taos.com>
Re: Why 'No child processes' after a system() call danrumney@warpmail.net
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 02 Mar 2007 23:50:06 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Cool Free Offers
Message-Id: <x74pp3q6bl.fsf@mail.sysarch.com>
and your perl question is?
<sound of massive plonkings>
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 02 Mar 2007 19:40:29 GMT
From: "Mumia W." <paduille.4060.mumia.w+nospam@earthlink.net>
Subject: Re: display datestamp in HTML
Message-Id: <N4%Fh.8130$tD2.3735@newsread1.news.pas.earthlink.net>
On 03/02/2007 10:40 AM, Phil M wrote:
> Hi all. I have am HTML web page where I upload a file which is always
> called document.pdf. Users get there, click on the icon and download
> the document.pdf.
>
> Below the icon/link where users click to get document, is there any
> way to display the datestamp of document.pdf?
>
> ie: the document you're about to download was updated: March 2 2007
> [...]
This is how you might find out the datestamp:
use POSIX qw(asctime);
my $filename = 'my.flat';
print asctime(localtime((stat $filename)[9]));
Read the documentation for asctime and stat. I'm assuming that you're a
Windows user:
Start->Run->"perldoc POSIX"
Start->Run->"perldoc -f stat"
After you have the datestamp in a string, printing it should be
elementary. Good luck.
------------------------------
Date: 2 Mar 2007 20:52:15 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: display datestamp in HTML
Message-Id: <slrneuh3k1.8cg.glennj@smeagol.ncf.ca>
At 2007-03-02 01:46PM, "Phil M" wrote:
> I also saved the file as an shtml, same results:
>
> http://www.greekradio.net/psa.shtml
Just renaming the file does not magically solve your problems for you.
You have to actually do something, like add an SSI directive:
<!--#flastmod file="document.pdf" -->
See http://httpd.apache.org/docs/1.3/howto/ssi.html
Does your web server have SSI enabled?
http://httpd.apache.org/docs/1.3/mod/mod_include.html
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
------------------------------
Date: Sat, 3 Mar 2007 02:29:11 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Error In DBI - Cannot execute multiple statements
Message-Id: <slrneuhjr7.q59.hjp-usenet2@yoyo.hjp.at>
On 2007-03-01 12:09, pankaj_wolfhunter@yahoo.co.in <pankaj_wolfhunter@yahoo.co.in> wrote:
> $dbh->do(q{
> spool test.sql
> select sysdate from dual
> spool off
> });
[...]
> What is wrong with the query?
"spool" is not SQL command.
Also, a newline in an SQL query doesn't terminat the query, so you tried
to execute the query "spool test.sql select sysdate from dual spool off",
which is almost certainly not what you wanted.
hp
--
_ | Peter J. Holzer | Es ist ganz einfach ihn zu verstehen, wenn
|_|_) | Sysadmin WSR | man nur alle wichtigen Worte im Satz durch
| | | hjp@hjp.at | andere ersetzt.
__/ | http://www.hjp.at/ | -- Nils Ketelsen in danr
------------------------------
Date: 2 Mar 2007 18:54:29 -0800
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Error In DBI - Cannot execute multiple statements
Message-Id: <1172890469.028845.279140@31g2000cwt.googlegroups.com>
On Mar 2, 8:29 pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2007-03-01 12:09, pankaj_wolfhun...@yahoo.co.in
> > $dbh->do(q{
> > spool test.sql
> > select sysdate from dual
> > spool off
> > });
> [...]
> > What is wrong with the query?
>
> "spool" is not SQL command.
True, but completely irrelevant. DBI doesn't care if the command
passed to do() is valid as per the SQL standard. As long as the
underlying RDMS understands it, it's fine.
> Also, a newline in an SQL query doesn't terminat the query, so you
> tried to execute the query "spool test.sql select sysdate from dual
> spool off", which is almost certainly not what you wanted.
That, however, is relevant.
Paul Lalli
------------------------------
Date: Fri, 02 Mar 2007 14:49:28 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 6.21 What's wrong with using grep in a void context?
Message-Id: <x7bqjbs9x3.fsf@mail.sysarch.com>
>>>>> "h" == h3xx <amphetamachine@gmail.com> writes:
h> On Mar 1, 2:03 pm, PerlFAQ Server <b...@stonehenge.com> wrote:
>> In perls older than 5.8.1, map suffers from this problem as well. But
>> since 5.8.1, this has been fixed, and map is context aware - in void
>> context, no lists are constructed.
h> Why isn't grep context-aware as well?!? I think of grep as the boring
h> sister-function of map.
context aware how? it already returns different things in scalar vs list
context. why would you call grep a boring sister function? first off it
was around in perl 4. secondly they do very different things (even if
map can emulate grep). grep is meant to filter an input list and map is
meant to generate a list from a list. those are not the same semantics
and it is good to have both funcs.
h> OK, enough complaining. I guess the reason using grep is wasteful
h> in a void context is that it's meant to get all the lines matching
h> an expression (or a block of code that evaluates true [read:
h> non-zero] when executed on $_), very similar to unix grep. It CAN
h> modify the list elements vicariously through $_ in something like
h> this:
grep in void context is totally meaningless. even worse IMO than map in
void context. neither should be used to modify the input list.
h> # changes the strings in @my_list and puts the modified lines matching
h> the s// into @changed_lines
h> @changed_lines = grep { s/foo/bar/g } @my_list;
h> ... and doing it with map has a little different results:
h> # changes the strings in @my_list and dumps each of them (regardless
h> of whether s// matched) into
h> # @duplicate_array. The two arrays are exact duplicates now.
h> @duplicate_array = map { s/foo/bar/g } @my_list;
it helps when you discuss this sort of stuff if you post working code:
perl -le '@a = qw( aba baa ) ; print map { s/a/z/g } @a'
22
s/// doesn't return the modified string. you need to use:
perl -le '@a = qw( aba baa ) ; print map { s/a/z/g ; $_ } @a'
zbzbzz
and even with the new optimization of map it is semantically misleading
to use it to modify its input list. map's primary and intended purpose
is to make a new list from an old one. the for modifier is a much op to
use when you want to modify something in place.
use the right function for the task at hand. map/grep/for are all there
for reasons.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 02 Mar 2007 20:52:15 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: Q on regex of LWP::Simple data
Message-Id: <esaa63$l6r$1@mlucom4.urz.uni-halle.de>
Len Philpot wrote:
> # unwrap this line
> my @cachepage = \
> get('http://www.geocaching.com/seek/cache_details.aspx?wp=GC115K4');
> # line in question (in @cachepage) looks like :
> # <p><span id="ShortDescription">Should be quick and easy.</span></p>
> foreach my $line (@cachepage)
> {
> if($line =~ /Should be quick/)
> {
> print("$line");
> }
> }
>
>
> Instead of printing only the line that contains "Should be quick", it
> prints every line.
After reading all the really good advice
given to yu by others here, i'd like
to point you in the direction mentioned
by Iain.
The minimum working solution for your
question "w/appropriate regex" would
therefore be:
...
my $cachepage = get 'http://www.geocaching.com/seek/cache_details.aspx?wp=GC115K4';
my $searchstr = 'Should be quick';
if( $cachepage =~ /^(.*?$searchstr.*?)$/m ) {
print "$1\n"
}
...
I read you are/have been a C programmer (as I am),
I'd like to stress the idea you should *really* try
to get somehow into the "regex metalanguage" because
knowing it would have enabled you to spit out a solution
after learning what "LWP::Simple::get" returns.
The Regex modifier /m (http://www.perl.com/doc/manual/html/pod/perlre.html)
does exaclty what you need here, it 'anchors' the expression
in parentheses (.*?$searchstr.*?) between line start and line end.
The conntent of the (first and only) parentheses will then
be available in the pattern match variable $1.
Regards
Mirco
------------------------------
Date: Fri, 2 Mar 2007 17:29:08 -0600
From: Len Philpot <len@philpot.org>
Subject: Re: Q on regex of LWP::Simple data
Message-Id: <1poe7hiwdn0hs$.1ttnppqkudph2$.dlg@40tude.net>
On Fri, 02 Mar 2007 20:52:15 +0100, Mirco Wahab wrote:
> The minimum working solution for your
> question "w/appropriate regex" would
> therefore be:
>
> ...
> my $cachepage = get 'http://www.geocaching.com/seek/cache_details.aspx?wp=GC115K4';
> my $searchstr = 'Should be quick';
>
> if( $cachepage =~ /^(.*?$searchstr.*?)$/m ) {
> print "$1\n"
> }
> ...
>
> I read you are/have been a C programmer (as I am),
Let me clarify - I find C fascinating and have played with it off and on
over the years. I hesitate to call myself a programmer in any language,
much less C (and it's been a while since I spent any serious time with
it), but I do find it very interesting. I'm not a programmer by
profession... although in the strictest sense of the term, I /have/ been
technically paid to write a couple of programs. :-)
> I'd like to stress the idea you should *really* try
> to get somehow into the "regex metalanguage" because
Absolutely. I'm a Solaris admin by day, so I use them here and again,
although I need to make an effort to learn it beyond just what I use on
the job.
> The conntent of the (first and only) parentheses will then
> be available in the pattern match variable $1.
That's what I had in mind (and have done, temporarily): to use a back
reference to grab what I need. The string I used above was a test case.
Actually I look for a specific set of tags followed by a specific HTML
ID value, which are hardwired in the regex, followed by the back
referenced payload.
Thanks.
--
---- Len Philpot -------- l e n @ p h i l p o t . o r g (no spaces)
------- ><> ------------- http://pages.suddenlink.net/lenphilpot/
------------------------------
Date: 2 Mar 2007 13:57:22 -0800
From: danrumney@warpmail.net
Subject: Why 'No child processes' after a system() call
Message-Id: <1172872642.799331.249290@z35g2000cwz.googlegroups.com>
Hi all,
I have a script (see below) that is driving me nuts.
It runs as a daemon on a RHEL box and does just about everything
correctly. It's job is to scan a hash of jobs every 15s to see if
there are any new ones that need to be performed.
Each time a new job is found, this script forks off a child to perform
the necessary task.
Prior to forking off the child, it runs a utility called 'cleanXML'
which is designed to remove invalid characters from an XML file.
I use system to call the utility. For some reason, the return code is
'No child processes'. But, the thing is, it has absolutley no problem
forking just a few lines later...
So my question is... what's going on!?! If I think about it, the
return value of -1 means that after the hidden fork() that system()
performs, the parent process couldn't find any child processes, which
means either that the fork() didn't work or that the child died before
the parent process could proceed... is that feasible?
Any other hypotheses would be warmly welcomed
Thanks,
Dan
#!/usr/bin/perl
use strict;
use svcNav::svcView; # Custom module
use svcNav::svcControl; # Custom module
use Data::Dumper;
use diagnostics;
sub message(@);
sub error(@);
sub wall(@);
my $access_log = "/var/log/svcObjectBrowserJobs.log";
my $error_log = "/var/log/svcObjectBrowserJobs.error.log";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, ">>$access_log" or die "Can't write to $access_log: $!";
open STDERR, ">>$error_log" or die "Can't write to $error_log: $!";
# Change to root so that unmounting filesystems will be possible
chdir '/';
my $canCleanXML = "no";
my $xmlCleaner = "/root/cleanXML"; #Custom utility that clears
invalid chars from an XML file
# Check to see if we can execute the cleanXML script
if ( -x $xmlCleaner )
{
$canCleanXML = "yes";
}
wall( "objectBrowser daemon started PID:" . $$ );
wall( "XML Cleaning will",
( $canCleanXML eq "yes" ) ? " " : " not ",
"be performed");
#
# In order to reset this daemon, simply put a job of type "reset" in
the queue
# The dameon will reset once there are no more running jobs
my $endLoop = "no";
my $runningJobs = 0;
my $resetJobId = 0;
# Main loop
do
{
# Scan the job queue no more often than every 15s
# The period may be longer, depending on how many jobs get started
in this
# pass through
sleep 15;
my $jobs = svcView::getJobs(); # get a hash of 'jobs'
# Throw out the jobs that have already failed and
# Count the running jobs
$runningJobs = 0;
my $nonFailedJobs = {};
foreach my $jobKey ( keys %$jobs )
{
if ( $jobs->{$jobKey}->{'type'} eq "reset" )
{
if ($endLoop eq "no")
{
wall("Reset request received");
$resetJobId = $jobKey;
$endLoop = "yes";
}
}
elsif ( defined( $jobs->{$jobKey}->{'pid'} ) )
{
$runningJobs++;
}
elsif ( $jobs->{$jobKey}->{'failed'} eq "no" )
{
$nonFailedJobs->{$jobKey} = $jobs->{$jobKey};
}
}
if (($runningJobs > 0) && ($endLoop eq "no"))
{
message("Found $runningJobs running jobs");
}
# Go through the non failed jobs and start parsing them up to a
maximum
# of 6 concurrent processes
foreach my $jobKey ( keys %$nonFailedJobs )
{
# Only start new jobs if the daemon is not going to end
if (( $runningJobs < 6 ) && ($endLoop eq "no"))
{
message( "Trying to start a "
. $jobs->{$jobKey}->{'type'}
. " job on fileId: "
. $nonFailedJobs->{$jobKey}->{'fileId'} );
# If XML Cleaning is enabled, we clean the file first
# I found that if this was done after the fork, it would
fail
# I've moved it here because it's pretty quick
my $cleaningOutcome = "Not performed";
if ( $canCleanXML eq "yes" )
{
my $fileId = $nonFailedJobs->{$jobKey}->{'fileId'};
my $xmlFile = svcView::getFileName($fileId);
message("Cleaning file: $xmlFile");
my @cleanArgs =
( $xmlCleaner, $xmlFile, $xmlFile . ".cleaned" );
# Run the cleaning utility
system(@cleanArgs);
if ( $? == -1 )
{
message("XML Cleaning failed, see error log");
error("Failed to execute XML Cleaner: $!");
$cleaningOutcome = "Failed due to cleaner not
executing";
}
elsif ( $? & 127 )
{
message("XML Cleaning failed, see errror log");
my $errMsg = sprintf(
"child died with signal %d, %s coredump\n",
( $? & 127 ),
( $? & 128 ) ? 'with' : 'without'
);
error($errMsg);
$cleaningOutcome = "Failed due to cleaner
terminating";
}
elsif ( ( $? >> 8 ) != 0 )
{
message("XML Cleaning failed, see errror log");
my $errMsg =
sprintf( "child exited with value %d\n", $? >>
8 );
error($errMsg);
$cleaningOutcome =
"Failed due to cleaner exiting with failure
code";
}
else
{
message("XML Cleaning successful");
$cleaningOutcome = "Cleaning completed
successfully";
`cp $xmlFile.cleaned $xmlFile`;
}
`rm $xmlFile.cleaned`;
}
# Now that the file is clean, we start a process to parse
it
$SIG{CHLD} = 'IGNORE';
my $jobPID = fork();
svcView::forked();
svcControl::forked();
if ( !defined($jobPID) )
{
error("Couldn't fork!");
}
elsif ( $jobPID != 0 )
{
# Daemon's code path
eval
{
wall( "Starting proc. ".$jobPID." for jobKey ".
$jobKey);
svcControl::markJobStarted( $jobKey, $jobPID );
};
if ($@)
{
error( "Daemon failed for some reason: " . $@ );
}
$runningJobs++;
sleep 10;
}
else
{
# Parsing code path
eval
{
my $fileId = $nonFailedJobs->{$jobKey}-
>{'fileId'};
my $trackNum = $nonFailedJobs->{$jobKey}-
>{'trackingNum'};
my $comment = $nonFailedJobs->{$jobKey}-
>{'comment'};
message( "Creating snap for File: $fileId ",
"with tracking number $trackNum ",
"and comment $comment");
my $parseResult = 0;
my $parseMessage = "";
eval
{
$parseResult =
svcControl::processSnapFile( $fileId,
$trackNum,
$comment,
\
$parseMessage );
};
# Check the outcome of the parsing and mark the
job
# appropriately
if ( $@ || $parseResult != 0 )
{
wall( "Job failed: " . $@ . " "
. $parseMessage
. "\nXML Cleaning: "
. $cleaningOutcome );
svcControl::markJobFailed( $jobKey,
$parseResult,
$parseMessage
. " XML Cleaning: "
. $cleaningOutcome );
}
else
{
message("Job finished");
svcControl::markJobDone( $jobKey,$fileId );
}
};
if ($@)
{
error( "Parsing process failed for some reason:
" . $@ );
}
exit;
}
}
}
} while (($endLoop eq "no") || ($runningJobs != 0) );
# If execution gets to here, then the while loop has ended, so the
script is
# about to end
svcControl::markJobDone($resetJobId, "NULL");
wall("Ending daemon");
#
# These subroutines are used to post messages into the log files
# You have to concatenate localtime with a string to get it in human
readable
# format, but you need to print a list so that @_ is read in a list
context
#
sub message(@)
{
print localtime() . ": " , @_ , "\n";
}
sub error(@)
{
print STDERR localtime() . ": " , @_ , "\n";
}
sub wall(@)
{
message(@_);
error(@_);
}
------------------------------
Date: Fri, 02 Mar 2007 23:35:38 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Why 'No child processes' after a system() call
Message-Id: <ex2Gh.2365$tv6.641@newssvr19.news.prodigy.net>
danrumney@warpmail.net wrote:
> Hi all,
> I have a script (see below) that is driving me nuts.
> It runs as a daemon on a RHEL box and does just about everything
> correctly. It's job is to scan a hash of jobs every 15s to see if
> there are any new ones that need to be performed.
> Each time a new job is found, this script forks off a child to perform
> the necessary task.
> Prior to forking off the child, it runs a utility called 'cleanXML'
> which is designed to remove invalid characters from an XML file.
> I use system to call the utility. For some reason, the return code is
> 'No child processes'. But, the thing is, it has absolutley no problem
> forking just a few lines later...
You don't check the return code from system, so you mean something
else. I assume that you mean $! says that.
What I think is happening is that when the system fails, it is setting
$? to -1, but it does not touch $!. So the contents of it are invalid
for you and represent something else (like some old wait from
elsewhere).
Here's an example:
$ cat /tmp/systest
#!/usr/bin/perl -w
use strict;
my $prog = '/tmp/noexist';
system($prog);
print "Error vars are $? and $!\n";
wait;
system($prog);
print "Error vars are $? and $!\n";
$ perl /tmp/systest
Can't exec "/tmp/noexist": No such file or directory at /tmp/perl line 5.
Error vars are 65280 and
Can't exec "/tmp/noexist": No such file or directory at /tmp/perl line 8.
Error vars are 65280 and No child processes
The only difference between the two invocations is that the wait() put
something in $! which was picked up later. It's not associated with the
failed fork/exec from system.
> So my question is... what's going on!?! If I think about it, the
> return value of -1 means that after the hidden fork() that system()
> performs, the parent process couldn't find any child processes, which
> means either that the fork() didn't work or that the child died before
> the parent process could proceed... is that feasible?
Most likely is that the system is failing because the code you're trying
to run is not executable (pathname, permissions, etc.)
--
Darren Dunham ddunham@taos.com
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: 2 Mar 2007 16:16:09 -0800
From: danrumney@warpmail.net
Subject: Re: Why 'No child processes' after a system() call
Message-Id: <1172880969.449775.82520@h3g2000cwc.googlegroups.com>
Thanks for that
However, it turns out, the problem is the line:
$SIG{CHLD} = 'IGNORE';
That tells the main loop to ignore signals from children of all forks,
so when you call system, the wait() call doesn't find any children.
I set
$SIG{CHLD} = 'DEFAULT';
before my system() call and the problem is resolved
Thanks,
Dan
------------------------------
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 189
**************************************