[26166] in Perl-Users-Digest
Perl-Users Digest, Issue: 8355 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 25 06:05:30 2005
Date: Thu, 25 Aug 2005 03:05:05 -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 Thu, 25 Aug 2005 Volume: 10 Number: 8355
Today's topics:
Re: Formatting XML output from a hashref <ron@savage.net.au>
Re: Can a Perl Programmer Pick up PHP quickly? <sisyphus1@nomail.afraid.org>
Re: FAQ 3.5 How do I debug my Perl programs? <sdn.girths00869@zoemail.net>
fjwD. check out this kick ass casino fjwD. <xzhvasqt@vxhuarpr.com>
Re: move information from HTTP::Request to CGI.pm <miroslav@suchy.cz>
Re: Obtaining verbose info for http transfers. (Anno Siegel)
Re: TimeDate conversion to string. <ranger_lp@hotmail.com>
Re: TimeDate conversion to string. <sdn.girths00869@zoemail.net>
Re: TimeDate conversion to string. <babacio@free.fr>
Re: TimeDate conversion to string. <tintin@invalid.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 25 Aug 2005 18:42:55 +1000
From: Ron Savage <ron@savage.net.au>
Subject: Re: Formatting XML output from a hashref
Message-Id: <2005825184255.152375@ron>
On Wed, 24 Aug 2005 04:43:33 +1000, Sam wrote:
Hi Sam
A recursive sub, altho tricky to write, would be the best way to process the=
hash keys and to manage the formatting.
------------------------------
Date: Thu, 25 Aug 2005 19:38:07 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Can a Perl Programmer Pick up PHP quickly?
Message-Id: <430d91b0$0$19001$afc38c87@news.optusnet.com.au>
"Mike" <mike@nospam.com>
> Can a Perl programmer pick up PHP easily?
Most definitely.
Always wear a condom.
Cheers,
Rob
------------------------------
Date: Thu, 25 Aug 2005 00:05:26 -0500
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: FAQ 3.5 How do I debug my Perl programs?
Message-Id: <Xns96BDB5BD4131sdn.comcast@216.196.97.136>
PerlFAQ Server <comdog@panix.com> wrote in
news:dee75k$m23$1@reader2.panix.com:
> --------------------------------------------------------------------
>
> 3.5: How do I debug my Perl programs?
>
[...]
> Have you tried the Perl debugger, described in perldebug? You can
> step through your program and see what it's doing and thus work
> out why what it's doing isn't what it should be doing.
To the FAQ maintainer(s):
Might I suggest adding a note about the excellent Devel::ptkdb
debugger? It requires Tk, and it doesn't come with perl, but it's a
great windowed debugger, in the style that many people coming to Perl
from other languages may be used to.
Just a thought.
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
------------------------------
Date: Thu, 25 Aug 2005 15:07:56 -0700
From: "Jeff Hanson" <xzhvasqt@vxhuarpr.com>
Subject: fjwD. check out this kick ass casino fjwD.
Message-Id: <wSbPe.10671$A1.7326@news.uswest.net>
Dear Casino Player,
YOU HAVE BEEN PREAPPROVED.
Receive $100 FREE at the Online Casino Of The Year 2002 when you open a new account.
DOWNLOAD AWARD WINNING CASINO GAMES
or
VISIT THEIR WEBSITE FOR MORE INFORMATION.
http://webmaster.windowscasino.com/SmartDownload.asp?affid=14409
WINDOWS CASINO FEATURES OVER
* 127 GAMES
* PROMPT PAYOUTS
* GENEROUS COMPS
* FREE CHIPS
Experience the diference in online gaming today!
js&cTKXW\K=UYClNCu9rkG8LY)gB<Qvgb_6HYi]j8>?#
------------------------------
Date: Thu, 25 Aug 2005 09:11:00 +0200
From: Miroslav Suchy <miroslav@suchy.cz>
Subject: Re: move information from HTTP::Request to CGI.pm
Message-Id: <dejr3l$55t$1@mrazik2.dkm.cz>
Hello again,
I was hard working on my problem (I've HTTP::Request and I to move its
iformation to CGI object) and I come to the smallest code. But it still does not
work and I do not know where can be a problem.
8<--cut
#!/usr/bin/perl
use strict;
use HTTP::Daemon ();
use CGI ();
my $daemon = HTTP::Daemon->new(
LocalAddr => 'my.domain.com',
LocalPort => 8888,
) or die "Cannot start daemon: $!\n";
my $i;
while (my $conn = $daemon->accept()) {
while (my $req = $conn->get_request()) {
my $url = $req->uri();
$ENV{'REQUEST_METHOD'}=$req->method();
$ENV{'CONTENT_TYPE'}=$req->header('Content-Type');
$ENV{'CONTENT_LENGTH'}=$req->header('Content-Length');
my $filename="/dev/shm/tmp.$$.".++$i;
print STDERR "$filename\n";
open INPUT, ">$filename" or die; # prepare stdin for CGI.pm
binmode INPUT;
print INPUT $req->content;
close INPUT;
open STDIN, "<$filename" or die; # redirect stdin
my $q = CGI->new;
my $id=$q->param('id');
my $ff=$q->param('file');
print STDERR "$id-$ff----\n";
my $res = HTTP::Response->new();
$res->header('Content-Type'=> 'text/html');
my $content=$q->start_html.$q->end_html;
$res->content_length(length($content));
$res->content($content);
$conn->send_response($res);
close STDIN;
}
$conn->close();
}
8<---cut
In first while loop is everything correct. But second and all additional loops
have the same content of $q as in first loop!!!!
STDERR look like this:
/dev/shm/tmp.18353.1
4159616-4159616.jpg----
/dev/shm/tmp.18353.2
4159616-4159616.jpg----
/dev/shm/tmp.18353.3
4159616-4159616.jpg----
It means $q->param('id') returns id from the first file, which contain:
$ head -n5 /dev/shm/tmp.18353.1
--xYzZY
Content-Disposition: form-data; name="id"
4159616
--xYzZY
but it should return id from the second file, which contain:
$ head -n5 /dev/shm/tmp.18353.2
--xYzZY
Content-Disposition: form-data; name="id"
4159620
--xYzZY
If I try to dump STDIN after the line:
open STDIN, "<$filename" or die; # redirect stdin
it is the same as content of file $filename
But CGI module somehow remember its state from first reading!!
How can I force CGI to re-read STDIN?
Or make I something wrong?
BTW: The request for this daemon is created using this code:
...
my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://my.domain.com:8888/',
[
id => $id,
file => ["$path$id.jpg"] ,
],
'Content_Type' => 'form-data',
);
Thanks in advance for any suggestion
Miroslav Suchy
------------------------------
Date: 25 Aug 2005 09:42:18 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Obtaining verbose info for http transfers.
Message-Id: <dek3pq$f0l$1@mamenchi.zrz.TU-Berlin.DE>
ko <kuujinbo@hotmail.com> wrote in comp.lang.perl.misc:
> Eric Schwartz wrote:
> > ko <kuujinbo@hotmail.com> writes:
> >
> >>sub verbose_http {
> >> push my @urls, shift;
> >> while (my $url = shift @urls) {
> >
> >
> > What's the point of this? Why not just
> > sub verbose_http {
> > my $url = shift;
> >
> > <snip rest of code>
> >
> > -=Eric
>
> Yes, could've use recursion:
>
> sub verbose_http {
> my $url = shift;
> my $r = $ua->get($url);
> if ($r->is_redirect) {
> print $r->headers->as_string . "\n\n";
> my $redirect = $r->header('Location');
> verbose_http($redirect);
> } elsif ($r->is_success) {
> print $r->content . "\n";
> }
> }
>
> Just a personal preference not to :)
Huh? I don't get it. How does one force you to use recursion and
the other doesn't?
sub foo {
my @urls = shift;
while ( my $url = shift @urls ) {
# do something
}
}
sub bar {
my $url = shift;
# do something
}
These do the same thing, except that foo() is unnecessarily roundabout.
Minor differences may result from "# do something" being enclosed in a
block in foo(), but not in bar(), but how foo() would avoid recursion
needed in bar() is beyond me.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Wed, 24 Aug 2005 21:13:00 -0400
From: "Tony" <ranger_lp@hotmail.com>
Subject: Re: TimeDate conversion to string.
Message-Id: <zW8Pe.18658$U63.3275@fe12.lga>
Thanks for the answers group. I got it to work.
Tony
"Joe Smith" <joe@inwap.com> wrote in message
news:ZsqdnUfNUaUEMZHeRVn-hA@comcast.com...
> Tony wrote:
>
>> $labelname = printf "REL_" . $proj[0] . "_%02d%02d%02d_%02d%02d%02d",
>>
>> Why do I get the extra 1 when adding \n?
>
> Because printf() returns true (1) when it succeeds.
> The generated string is going directly to STDOUT, not to $labelname.
------------------------------
Date: Thu, 25 Aug 2005 00:00:22 -0500
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: TimeDate conversion to string.
Message-Id: <Xns96BDA7E31113sdn.comcast@216.196.97.136>
"Tony" <ranger_lp@hotmail.com> wrote in
news:XdUOe.7758$KX7.6778@fe10.lga:
> I'm trying to use the output of the the date/time from localtime into
> a label.:
>
> ($sec,$min,$hour,$mday,$mon,$year,$wday,
> $yday,$isdst)=localtime(time);
> $year = ($year + 1900) - 2000;
> $labelname = printf "REL_" . $proj[0] . "_%02d%02d%02d_%02d%02d%02d",
> $hour,$min,$sec,$mon+1,$mday,$year;
> print "$labelname\\n";
May I suggest using the Time::Format module?
$labelname = "REL_$proj[0]_$time{hhmmss_mmddyy}";
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
------------------------------
Date: Thu, 25 Aug 2005 08:42:08 +0200
From: Babacio <babacio@free.fr>
Subject: Re: TimeDate conversion to string.
Message-Id: <m2irxuv7pb.fsf@baba.ba>
"Eric J. Roode"
> May I suggest using the Time::Format module?
>
> $labelname = "REL_$proj[0]_$time{hhmmss_mmddyy}";
Or DateTime and its friends ? It is very nice because it offers
(almost) everything you can dream of, like easter date computation, but
is still very simple to use (and there is more than a way to do
everything).
For example :
use DateTime;
use DateTime::Locale;
$dt = DateTime->now( locale => 'en' );
print $dt->strftime("This is %A, %B %d of %Y.\n");
Result :
This is Thursday, August 25 of 2005.
Other example :
$dt = DateTime->now( locale => 'es' );
print $dt->strftime("Estamos el %A %d de %B %Y.\n");
Result :
Estamos el jueves 25 de agosto 2005.
--
Bé erre hue ixe eu elle, Bruxelles.
------------------------------
Date: Thu, 25 Aug 2005 21:11:44 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: TimeDate conversion to string.
Message-Id: <pXfPe.5679$iM2.560886@news.xtra.co.nz>
"Tony" <ranger_lp@hotmail.com> wrote in message
news:XdUOe.7758$KX7.6778@fe10.lga...
> I'm trying to use the output of the the date/time from localtime into a
> label.:
>
> ($sec,$min,$hour,$mday,$mon,$year,$wday,
> $yday,$isdst)=localtime(time);
> $year = ($year + 1900) - 2000;
Y21K bug!!!
> $labelname = printf "REL_" . $proj[0] . "_%02d%02d%02d_%02d%02d%02d",
> $hour,$min,$sec,$mon+1,$mday,$year;
> print "$labelname\\n";
>
> The problem is that when I input $labelname into a system command, an
> error is returned saying
>
> REL_Tony_021138_0824051
> cleartool: Error: Name cannot be an integer: "1".
> cleartool: Error: Unable to create label type "1".
>
> Why do I get the extra 1 when adding \n?
> How can I make this a string so it will be read as a string?
I'd do it like:
use POSIX 'stftime';
my $labelname = strftime "REL_$proj[0]_%H%M%S%m%d%y\n", localtime;
------------------------------
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 V10 Issue 8355
***************************************