[31298] in Perl-Users-Digest
Perl-Users Digest, Issue: 2543 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 8 06:09:44 2009
Date: Sat, 8 Aug 2009 03:09:08 -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 Sat, 8 Aug 2009 Volume: 11 Number: 2543
Today's topics:
Re: conditional modules <john1949@yahoo.com>
DBI fetchall_arratref, JSON and converting numeric "sti <seven.reeds@gmail.com>
Re: DBI fetchall_arratref, JSON and converting numeric <ben@morrow.me.uk>
EARN free with ptc <adnanhameed750@gmail.com>
Re: FAQ 7.27 How can I comment out a large block of per <brian.d.foy@gmail.com>
Re: FAQ 7.27 How can I comment out a large block of per <kst-u@mib.org>
Re: FAQ 7.27 How can I comment out a large block of per <uri@stemsystems.com>
Re: FAQ 7.29 How can I use a variable as a variable nam <brian.d.foy@gmail.com>
Re: FAQ 8.14 How do I modify the shadow password file o <seven.reeds@gmail.com>
Re: FAQ 8.14 How do I modify the shadow password file o <brian.d.foy@gmail.com>
Re: FAQ 8.18 How can I do an atexit() or setjmp()/longj <brian.d.foy@gmail.com>
Re: FAQ 8.18 How can I do an atexit() or setjmp()/longj <ben@morrow.me.uk>
Re: FAQ 8.18 How can I do an atexit() or setjmp()/longj <nospam-abuse@ilyaz.org>
Re: FAQ 8.18 How can I do an atexit() or setjmp()/longj <uri@stemsystems.com>
Re: FAQ 8.18 How can I do an atexit() or setjmp()/longj <ben@morrow.me.uk>
Re: Function prototype (Tim McDaniel)
Re: Function prototype <ben@morrow.me.uk>
LWP logging problems <r.ted.byers@gmail.com>
Re: Perl process as a unix background process <hjp-usenet2@hjp.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 8 Aug 2009 09:34:28 +0100
From: "John" <john1949@yahoo.com>
Subject: Re: conditional modules
Message-Id: <h5jdaf$bkt$1@news.albasani.net>
Thank you, gentlemen, that was very useful.
Regards
John
------------------------------
Date: Fri, 7 Aug 2009 22:18:45 -0700 (PDT)
From: "seven.reeds" <seven.reeds@gmail.com>
Subject: DBI fetchall_arratref, JSON and converting numeric "sting" to "number"
Message-Id: <5a37a80e-3373-45e4-aac5-c04480462d25@h30g2000vbr.googlegroups.com>
Hi,
I am pulling data from some fairly simple database tables. I have a
simple SELECT query for each table and I can do the fetchall_arrayref
just fine. I want to format the returned data into a JSON string. I
am doing this with only one problem. The data returned from the fetch
is all "string"ified. If I have a table that has a numeric "id" field
then the default JSON result has that column as a set of numbers in
double quotes.
I know that I can loop over the returned array and "add zero" to the
numeric strings to have the JSON converter (JSON::Syck) treat them as
numbers. This works but looking at the code makes me wonder if there
is a more Perlesque way to do this. I've tried using map() on the
arrayref but my understanding is too shallow to make that work yet.
Ideas?
------------------------------
Date: Sat, 8 Aug 2009 06:48:56 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: DBI fetchall_arratref, JSON and converting numeric "sting" to "number"
Message-Id: <87gvk6-72c1.ln1@osiris.mauzo.dyndns.org>
Quoth "seven.reeds" <seven.reeds@gmail.com>:
>
> I am pulling data from some fairly simple database tables. I have a
> simple SELECT query for each table and I can do the fetchall_arrayref
> just fine. I want to format the returned data into a JSON string. I
> am doing this with only one problem. The data returned from the fetch
> is all "string"ified. If I have a table that has a numeric "id" field
> then the default JSON result has that column as a set of numbers in
> double quotes.
>
> I know that I can loop over the returned array and "add zero" to the
> numeric strings to have the JSON converter (JSON::Syck) treat them as
> numbers. This works but looking at the code makes me wonder if there
> is a more Perlesque way to do this. I've tried using map() on the
> arrayref but my understanding is too shallow to make that work yet.
Something like
use Scalar::Util qw/looks_like_number/;
for (@$results) {
$_ += 0
if looks_like_number $_;
}
seems perfectly Perlish to me. 'map' is not helpful here, unless you
wanted to keep the original arrayref around unmodified; in that case you
could use
my $new = [ map { $_ += 0 if looks_like_number $_ } @$old ]
'map' is just the same as 'for', except it collects up the results and
returns them as a list. If you don't need the returned list, you should
use 'for' instead.
(I presume you've read the comment at the top of JSON::Syck suggesting
JSON::XS instead? It won't help you here--it uses the same heuristic--
but it's supposed to be both faster and more correct.)
Ben
------------------------------
Date: Sat, 8 Aug 2009 00:36:14 -0700 (PDT)
From: adnan ji <adnanhameed750@gmail.com>
Subject: EARN free with ptc
Message-Id: <ea24f565-0495-4468-b336-8c67bff0c258@13g2000prl.googlegroups.com>
EARN MONEY free ONLINE WITH TRUSTED WEBSITES MORE VISIT www.ptcpakistan.blogspot.com
------------------------------
Date: Sat, 08 Aug 2009 02:35:27 +0100
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of perl code?
Message-Id: <080820090235278372%brian.d.foy@gmail.com>
In article <lnzlahpst4.fsf@nuthaus.mib.org>, Keith Thompson
<kst-u@mib.org> wrote:
> PerlFAQ Server <brian@stonehenge.com> writes:
> > 7.27: How can I comment out a large block of perl code?
> IHMO it's also worth mentioning that you can simply insert a '#'
> character at the beginning of each line.
The implicit motivation of the question is how to comment out the code
without doing that. :)
------------------------------
Date: Fri, 07 Aug 2009 19:33:25 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: FAQ 7.27 How can I comment out a large block of perl code?
Message-Id: <lniqgzghl6.fsf@nuthaus.mib.org>
brian d foy <brian.d.foy@gmail.com> writes:
> In article <lnzlahpst4.fsf@nuthaus.mib.org>, Keith Thompson
> <kst-u@mib.org> wrote:
>
>> PerlFAQ Server <brian@stonehenge.com> writes:
>> > 7.27: How can I comment out a large block of perl code?
>
>> IHMO it's also worth mentioning that you can simply insert a '#'
>> character at the beginning of each line.
>
> The implicit motivation of the question is how to comment out the code
> without doing that. :)
Perhaps, but somebody might ask the question without realizing that
the obvious way is to insert '#' characters.
I suggest at least saying something like:
Apart from the obvious method of inserting a '#' at the beginning
of each line, you can ...
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
------------------------------
Date: Fri, 07 Aug 2009 23:50:58 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of perl code?
Message-Id: <87k51fgdzx.fsf@quad.sysarch.com>
>>>>> "KT" == Keith Thompson <kst-u@mib.org> writes:
KT> brian d foy <brian.d.foy@gmail.com> writes:
>> In article <lnzlahpst4.fsf@nuthaus.mib.org>, Keith Thompson
>> <kst-u@mib.org> wrote:
>>
>>> PerlFAQ Server <brian@stonehenge.com> writes:
>>> > 7.27: How can I comment out a large block of perl code?
>>
>>> IHMO it's also worth mentioning that you can simply insert a '#'
>>> character at the beginning of each line.
>>
>> The implicit motivation of the question is how to comment out the code
>> without doing that. :)
KT> Perhaps, but somebody might ask the question without realizing that
KT> the obvious way is to insert '#' characters.
KT> I suggest at least saying something like:
KT> Apart from the obvious method of inserting a '#' at the beginning
KT> of each line, you can ...
but that is the best way to do this. the issue then is mentioning that
most programming oriented editors with a perl mode will have support for
this. if not, you can use one of the other techniques like pod markup to
do it.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Sat, 08 Aug 2009 02:34:06 +0100
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 7.29 How can I use a variable as a variable name?
Message-Id: <080820090234063498%brian.d.foy@gmail.com>
In article <ln8wi2q9pl.fsf@nuthaus.mib.org>, Keith Thompson
<kst-u@mib.org> wrote:
> PerlFAQ Server <brian@stonehenge.com> writes:
> [..]
> > 7.29: How can I use a variable as a variable name?
> >
> > Beginners often think they want to have a variable contain the name of a
> > variable.
> >
> > $fred = 23;
> > $varname = "fred";
> > ++$$varname; # $fred now 24
> >
> > This works *sometimes*, but it is a very bad idea for two reasons.
> >
> > The first reason is that this technique *only works on global
> > variables*.
> [snip]
>
> This FAQ should probably mention that you *can* have a variable
> containing a variable name, if you use eval, like this:
I need to rewrite this answer anyway, so I'll consider how to at once
tell people how to do it and not to do it. :)
------------------------------
Date: Fri, 7 Aug 2009 22:04:19 -0700 (PDT)
From: "seven.reeds" <seven.reeds@gmail.com>
Subject: Re: FAQ 8.14 How do I modify the shadow password file on a Unix system?
Message-Id: <6c6f1ac4-5c31-4bb2-92ba-f850216729bd@g6g2000vbr.googlegroups.com>
This may be a bit of a non sequitor for this group and topic but...
using pwd_mkdb is an expensive operation. The larger your password
table the worse it gets. I once managed a password table with ~30,000
entries (I kid you not, BSDiOS almost 10 years ago). If you are
making changes I strongly suggest batching them. The rebuild time for
1 or N records in a batch is about the same. The rebuild time for N
records in series is unbearable.
------------------------------
Date: Sat, 08 Aug 2009 02:31:54 +0100
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.14 How do I modify the shadow password file on a Unix system?
Message-Id: <080820090231545586%brian.d.foy@gmail.com>
In article <h5g1d9$k5m$1@aioe.org>, Alan Curry <pacman@kosh.dhis.org>
wrote:
> In article <lnhbwkj35j.fsf@nuthaus.mib.org>,
> Keith Thompson <kst-u@mib.org> wrote:
> >PerlFAQ Server <brian@stonehenge.com> writes:
> >> 8.14: How do I modify the shadow password file on a Unix system?
> This whole FAQ entry is nothing but a disguised rant (originally written by
> Tom Christiansen, I'll bet)
I think you are right, and this question should disappear from the FAQ.
------------------------------
Date: Sat, 08 Aug 2009 02:37:18 +0100
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.18 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Message-Id: <080820090237185022%brian.d.foy@gmail.com>
In article <lniqh4o31c.fsf@nuthaus.mib.org>, Keith Thompson
<kst-u@mib.org> wrote:
> PerlFAQ Server <brian@stonehenge.com> writes:
> > 8.18: How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
> >
> > Release 5 of Perl added the END block, which can be used to simulate
> > atexit(). Each package's END block is called when the program or thread
> > ends (see perlmod manpage for more details).
> Since Perl 5 is so old, I suggest it's not worth mentioning when this
> was added. The END block is just a feature of Perl.
I'm not even sure what the point of the question is. END blocks aren't
good for exception handling because you're not really handling
anything; you're just getting ready to stop.
This might be another candidate for the bit bucket.
------------------------------
Date: Sat, 8 Aug 2009 03:24:04 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 8.18 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Message-Id: <474vk6-5ko2.ln1@osiris.mauzo.dyndns.org>
Quoth brian d foy <brian.d.foy@gmail.com>:
> > PerlFAQ Server <brian@stonehenge.com> writes:
> > > 8.18: How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
<snip>
>
> I'm not even sure what the point of the question is. END blocks aren't
> good for exception handling because you're not really handling
> anything; you're just getting ready to stop.
>
> This might be another candidate for the bit bucket.
This falls into the general category of 'Perl for C programmers', which
is maybe not as useful as it used to be. The question still makes sense
if the '(Exception handling)' is removed, though it probably ought to be
two questions ('How do I do atexit()' and 'How do I so setjmp()').
Since there are appropriate pointers in POSIX under atexit/setjmp/
longjmp (and a whole lot of other C functions that don't have direct
equivalents in Perl), maybe a general 'How do I call <some standard C
function>' question that points to perldoc POSIX would be useful
instead.
Ben
------------------------------
Date: Sat, 8 Aug 2009 04:01:02 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: FAQ 8.18 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Message-Id: <slrnh7ptkv.nfr.nospam-abuse@chorin.math.berkeley.edu>
On 2009-08-08, Ben Morrow <ben@morrow.me.uk> wrote:
>> > > 8.18: How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
><snip>
>>
>> I'm not even sure what the point of the question is. END blocks aren't
>> good for exception handling because you're not really handling
>> anything; you're just getting ready to stop.
>>
>> This might be another candidate for the bit bucket.
>
> This falls into the general category of 'Perl for C programmers', which
> is maybe not as useful as it used to be. The question still makes sense
> if the '(Exception handling)' is removed, though it probably ought to be
> two questions ('How do I do atexit()' and 'How do I so setjmp()').
>
> Since there are appropriate pointers in POSIX under atexit/setjmp/
> longjmp (and a whole lot of other C functions that don't have direct
> equivalents in Perl), maybe a general 'How do I call <some standard C
> function>' question that points to perldoc POSIX would be useful
> instead.
I somehow miss WHAT is this discussion about? AFAIK, END {} blocks ARE
designed for exception handling. And I do not see what POSIX has to
do with END{} being a proper substitute for call_at_exit...
Puzzled,
Ilya
------------------------------
Date: Fri, 07 Aug 2009 23:54:36 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 8.18 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Message-Id: <87fxc3gdtv.fsf@quad.sysarch.com>
>>>>> "bdf" == brian d foy <brian.d.foy@gmail.com> writes:
bdf> In article <lniqh4o31c.fsf@nuthaus.mib.org>, Keith Thompson
bdf> <kst-u@mib.org> wrote:
>> PerlFAQ Server <brian@stonehenge.com> writes:
>> > 8.18: How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
>> >
>> > Release 5 of Perl added the END block, which can be used to simulate
>> > atexit(). Each package's END block is called when the program or thread
>> > ends (see perlmod manpage for more details).
>> Since Perl 5 is so old, I suggest it's not worth mentioning when this
>> was added. The END block is just a feature of Perl.
bdf> I'm not even sure what the point of the question is. END blocks aren't
bdf> good for exception handling because you're not really handling
bdf> anything; you're just getting ready to stop.
bdf> This might be another candidate for the bit bucket.
atexit is what END blocks do. setjmp/longjump are handled by eval BLOCK
and die. why these are mentioned together is the real question. do some
consider atexit an exception? it is a special case one if that and perl
doesn't do much other than offer END. the other is real and there are
modules that support higher level exception handling that might be
mentioned. i think this should be split into two FAQ entries and each
one can be properly addressed. the atexit is just END and is a simple
one. the exception handling is more complex and needs its own space.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Sat, 8 Aug 2009 05:42:02 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 8.18 How can I do an atexit() or setjmp()/longjmp()? (Exception handling)
Message-Id: <q9cvk6-g2s2.ln1@osiris.mauzo.dyndns.org>
Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
>
> I somehow miss WHAT is this discussion about? AFAIK, END {} blocks ARE
> designed for exception handling. And I do not see what POSIX has to
> do with END{} being a proper substitute for call_at_exit...
Nothing beyond this entry
atexit atexit() is C-specific: use "END {}" instead, see perlsub.
The documentation in POSIX.pm is a good place to start if you know how
to do something in C and want to do it in Perl.
Ben
------------------------------
Date: Sat, 8 Aug 2009 00:38:08 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Function prototype
Message-Id: <h5ihdg$1f0$1@reader1.panix.com>
On Aug 6, 5:45 pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> See why Perl's prototypes are nearly always not what you are looking
> for:
>
> http://www.perl.com/language/misc/fmproto.html
pavunkumar <pavun.bks@gmail.com> wrote:
> I want to write a function , that should accept specific
> number of arguments .
In article <slrnh7lnah.e80.tadmc@tadmc30.sbcglobal.net>,
Tad J McClellan <tadmc@seesig.invalid> wrote:
> Perl's prototypes do not do that...
$ perl -e 'sub add($$) { return $_[0] + $_[1]; }; print add(3), "\n";'
Not enough arguments for main::add at -e line 1, near "3)"
Execution of -e aborted due to compilation errors.
$ perl -e 'sub add($$) { return $_[0] + $_[1]; }; print add(3,4,5), "\n";'
Too many arguments for main::add at -e line 1, near "5)"
Execution of -e aborted due to compilation errors.
Looks to me like they DID "accept specific numbers of arguments" in
those cases.
I love compile-time checking and I wish there was more.
I use Perl sub prototypes. I declare subs before use. I always call
with parens when calling my own functions. I only use a fixed number
of scalars (for example, ($$$$)) or some scalars followed by an
optional list (for example, ($$$@)) or explicit documentation that it
accepts a list (@). Where there's a scalar argument, by gum, I pass
in a scalar: if I code "sub add($$)", I expect "add(@two_elements)"
to die.
And a few programs where I used
sub my_chomp(;\$)
sub trim(;\$)
I coded them to chomp | trim a scalar variable in-place, but if no
scalar is provided, process $_. And a few more rare cases, but
nothing weird. For example, if I want a ref argument, I do it myself.
This catches, at compile time, almost every error that I make with
arguments, without the bother of coding a die (which wouldn't fire at
compile time anyway).
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: Sat, 8 Aug 2009 02:11:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Function prototype
Message-Id: <luvuk6-m9n2.ln1@osiris.mauzo.dyndns.org>
Quoth tmcd@panix.com:
>
> And a few programs where I used
> sub my_chomp(;\$)
> sub trim(;\$)
> I coded them to chomp | trim a scalar variable in-place, but if no
> scalar is provided, process $_.
If you have 5.10, you can use the '_' prototype character for that
behaviour. (There's no need for the '\': $_[0] is passed by reference.
The fact that you're directly manipulating elements of @_ is geed
documentation that you're using pass-by-reference semantics.)
Ben
------------------------------
Date: Fri, 7 Aug 2009 15:09:12 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: LWP logging problems
Message-Id: <51acddbc-7b58-4cf7-8b26-e0d146bf6eb7@p36g2000vbn.googlegroups.com>
Up until yesterday, the following statements produced a nice log:
use LWP::RobotUA;
use LWP::UserAgent;
BEGIN { $LWP::DebugFile::outname = 'lwp.log' }
use LWP::DebugFile ('+');
This is on Windows, using Activestate Perl 5.10.0 Build 1004
Then, late yesterday afternoon, I used PPM to get a few more logging
packages, and now no longer produces output. I need to know if what
logging packages may conflict with LWP::DebugFile in such a ways as to
prevent me from getting logging information from LWP.
I'd also tried the following, from the FAQ, with no joy (no output
from LWP::DebugFile):
my $conf = q(
log4perl.logger = TRACE, FileApp, ScreenApp
log4perl.appender.FileApp =
Log::Log4perl::Appender::File
log4perl.appender.FileApp.filename = test.log
log4perl.appender.FileApp.layout = PatternLayout
log4perl.appender.FileApp.layout.ConversionPattern = %d> %m%n
log4perl.appender.Logfile = Log::Dispatch::FileRotate
log4perl.appender.Logfile.filename = test.rotate.log
log4perl.appender.Logfile.max = 5
log4perl.appender.Logfile.DatePattern = yyyy-MM-dd
log4perl.appender.Logfile.TZ = EST
log4perl.appender.Logfile.layout = \
Log::Log4perl::Layout::PatternLayout
log4perl.appender.Logfile.layout.ConversionPattern = %d %m %n
log4perl.appender.ScreenApp =
Log::Log4perl::Appender::Screen
log4perl.appender.ScreenApp.stderr = 0
log4perl.appender.ScreenApp.layout = PatternLayout
log4perl.appender.ScreenApp.layout.ConversionPattern = %d> %m
%n
);
# Initialize logging behaviour
Log::Log4perl->init( \$conf );
Log::Log4perl->infiltrate_lwp();
I do not know if my configuration above is helpful, as I was hoping to
test a single file that would grow indefinitely and a file that would
be rotated out at midnight, along with logging info to the screen, all
in one go, but even if this is a problem, it certainly does not affect
the whole program, copied from the same FAQ, appended below.
Something is stopping LWP::DebugFile from producing output (and in my
original code, configured to use a log file, no log file is created).
WHY??? :-(
Thanks
Ted
The appended program, copied directly from the FAQ, produces the
following output:
----from the Emacs output buffer-------------
Compilation started at Fri Aug 07 17:48:06
C:/Perl/bin\perl.exe -w c:/work/logging.test.2.pl
Success: Received 108787
Compilation finished at Fri Aug 07 17:48:07
----------------------end of OP---------------------
The FAQ says it should produce the following
----------beginning quote from
FAQ--------------------------------------
This will generate the following output on STDERR:
174 INFO LWP::UserAgent::new-164 ()
208 INFO LWP::UserAgent::request-436 ()
211 INFO LWP::UserAgent::send_request-294 GET http://amazon.com
212 DEBUG LWP::UserAgent::_need_proxy-1123 Not proxied
405 INFO LWP::Protocol::http::request-122 ()
859 DEBUG LWP::Protocol::collect-206 read 233 bytes
863 DEBUG LWP::UserAgent::request-443 Simple response: Found
869 INFO LWP::UserAgent::request-436 ()
871 INFO LWP::UserAgent::send_request-294
GET http://www.amazon.com:80/exec/obidos/gateway_redirect
872 DEBUG LWP::UserAgent::_need_proxy-1123 Not proxied
873 INFO LWP::Protocol::http::request-122 ()
1016 DEBUG LWP::UserAgent::request-443 Simple response: Found
1020 INFO LWP::UserAgent::request-436 ()
1022 INFO LWP::UserAgent::send_request-294
GET http://www.amazon.com/exec/obidos/subst/home/home.html/
1023 DEBUG LWP::UserAgent::_need_proxy-1123 Not proxied
1024 INFO LWP::Protocol::http::request-122 ()
1382 DEBUG LWP::Protocol::collect-206 read 632 bytes
...
2605 DEBUG LWP::Protocol::collect-206 read 77 bytes
2607 DEBUG LWP::UserAgent::request-443 Simple response: OK
Success: Received 42584
------end of quote---------------------------
------------logging.test.pl code------copied directly from teh FAQ,
for your convenience----------------------
use LWP::UserAgent;
use HTTP::Request::Common;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init(
{ category => "LWP::Debug",
level => $DEBUG,
layout => "%r %p %M-%L %m%n",
});
package LWP::Debug;
use Log::Log4perl qw(:easy);
*trace = *INFO;
*conns = *DEBUG;
*debug = *DEBUG;
package main;
my $ua = LWP::UserAgent->new();
my $resp = $ua->request(GET "http://amazon.com");
if($resp->is_success()) {
print "Success: Received ", length($resp->content()), "\n";
} else {
print "Error: ", $resp->code(), "\n";
}
------------------------------
Date: Sat, 8 Aug 2009 09:44:21 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Perl process as a unix background process
Message-Id: <slrnh7qb6m.4fg.hjp-usenet2@hrunkner.hjp.at>
On 2009-08-07 16:32, gbostock@excite.com <gbostock@excite.com> wrote:
> On Aug 7, 10:16 am, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
>> gbost...@excite.com wrote:
>> > I'm experiencing some strange behavior with a certain perl program
>> > when trying to run it as a unix background process. This process runs
>> > with no problems at the terminal.
>> > When I do:
>> > (prompt)$myperl.pl &
>>
>> > The process starts running, output comes to the terminal but the
>> > prompt doesn't come back.
No prompt? Are you sure? Or is it possible that you just don't notice
the prompt because it is buried somewhere between the output from
myperl.pl?
>> > If there is any input at the terminal a
>> > message appears saying that the process has stopped.
"If there is any input" or "If you press return"? Please be specific.
The bash prints messages about stopped jobs only after you enter a
complete command (the zsh displays it immediately and then redisplays
the prompt and the partially entered command, if any).
Also, what is the exact message?
>> > If I do:
>> > (prompt)$ nohup myperl.pl &
>>
>> > the same thing happens
I.e. you still get output from myperl.pl on the screen? This is also
strange, because nohup normally redirects stdout and stderr to
"nohup.out".
(on some but not all systems, nohup also redirects stdin from
/dev/null).
If you don't get output you shouldn't write "the same thing happens",
but describe what happens.
A good way (if you are familiar with Unix system calls) to find out what
a program is doing is to use strace (Linux) or truss (Solaris) or tusc
(HP-UX) or whatever it is called on your system.
>> > If I do:
>> > (prompt)$myother.pl &
>>
>> > then I get the prompt back and the process runs in the background just
>> > fine and continues when I use the terminal as usual.
>>
>> > So the question is: Does anybody have any idea what could be in the
>> > myperl.pl that could prevent it from running in the background?
>>
>> Possibly it's reading from STDIN.
>
> Nope, it reads from files, but the problem manifests before it gets to
> the file read.
>> > Please don't ask me to post the code as it is proprietary.
>>
>> Instead, you could comment out large chunks of your code to
>> narrow down where it might occur. Once you narrow it down
>> to the particular line(s), then you can post your short example.
>
> Narrow it down on what basis? Guessing?
Not quite. First comment out all the code which you think is never
called before the process is stopped (you say that it is stopped before
the first file is opened, so I guess this will get rid of the bulk of
the program. Verify that it is still stopped. Then comment out about
half of the remaining program, verify that the problem still exists. If
it doesn't, remove the comments and comment out the other half. Repeat
until you cannot remove any more without solving the problem. By then
the program is almost certainly small enough that you can see the cause
or that you can post it here.
> - Hide quoted text -
>>
>> - Show quoted text -
>
Please remove these lines before posting. They contain no useful
information.
hp
------------------------------
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 2543
***************************************