[25125] in Perl-Users-Digest
Perl-Users Digest, Issue: 7375 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 8 03:05:42 2004
Date: Mon, 8 Nov 2004 00:05:07 -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 Mon, 8 Nov 2004 Volume: 10 Number: 7375
Today's topics:
Re: an original perldoc viewer <ioneabu@yahoo.com>
Re: an original perldoc viewer <1usa@llenroc.ude.invalid>
Re: Binary files in PERL? <benkhoo@copperblue.per.sg>
Re: Check POP3 E-mail (krakle)
FAQ 5.22: How do I randomly update a binary file? <comdog@panix.com>
Firefox broswer staring Perl CGI <g-preston1@ti.com>
Re: Firefox broswer staring Perl CGI <postmaster@castleamber.com>
Re: Problem with cp in system call running Mac OS X <tim@vegeta.ath.cx>
Re: Q: re Inline and Benchmark <nospam-abuse@ilyaz.org>
Re: Q: re Inline and Benchmark <kalinaubears@iinet.net.au>
Spam-free Mailto.pl or similar prog? <madra@rua.net>
Re: Spam-free Mailto.pl or similar prog? <1usa@llenroc.ude.invalid>
sub refs in qq strings <jeff@spamalanadingong.com>
Re: sub refs in qq strings <uri@stemsystems.com>
Re: sub refs in qq strings <1usa@llenroc.ude.invalid>
Re: sub refs in qq strings <postmaster@castleamber.com>
Re: Upload meter for a CGI perl script <sean.berry2@cox.net>
Re: Upload meter for a CGI perl script <usenet_05_08_2004@stuartmoore.org.uk>
Re: Upload meter for a CGI perl script <sean.berry2@cox.net>
Re: Using $SIG{"ALRM"} assignment inside a subroutine <a@ry.ca>
Re: Using $SIG{"ALRM"} assignment inside a subroutine <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 07 Nov 2004 22:21:26 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: an original perldoc viewer
Message-Id: <10otm79211him89@news.supernews.com>
Ben Morrow wrote:
>
> Quoth ioneabu@yahoo.com:
>> Ben Morrow wrote:
>>
>> >
>> > Quoth ioneabu@yahoo.com:
>> >> I have been reprimanded for my lack of knowledge of perldoc material
>> >> so I
>> >> have decided to do more reading. I realized that I am often (%50 of
>> >> the time) working on a machine that does not have Perl but is
>> >> connected to the
>> >> internet. My first thought was to go to perldoc.com, but it seemed
>> >> to be
>> >> down tonight, so I wrote a simple home-made solution to get by for
>> >> now. I was hoping pod2html would format my perldocs but it did not
>> >> work when I
>> >> tried: pod2html perltoc (maybe perldoc pod2html says how to do it).
>> >> Here
>> >> it is. Improvements, especially in output formatting, would be
>> >> welcome.
>> >>
>> >> #!/usr/bin/perl
>> >
>> > USE TAINT MODE.
>> >
>> > #!/usr/bin/perl -T
>> >
>> > This would have caught the error you noticed for yourself.
>> >
>> > Ben
>> >
>>
>> ok, I read perlsec and did a little testing...
>> ------------------
>> #!/usr/bin/perl -T
>>
>> my $a = 'perl';
>> `perldoc $a`;
>> ------------------
>> me> perl -c test.pl
>> Perl> Too late for "-T" option at test.pl line 1.
>> (what does that mean?)
>
> This has been answered already...
>
>> me> ./test.pl
>> Perl> Insecure $ENV{PATH} while running with -T switch at ./test.pl
>> line 4. (ok, this is useful and expected)
>>
>> now test the CGI program with -T...with the protective regex
>> screening removed...
>> ------------------------------------------
>> #!/usr/bin/perl -T
>>
>> use CGI qw(:standard);
>> if (param('display'))
>> {
>> if (my $doc = param('docname'))
>> {
>> $a = `perldoc $doc`; #this is the dangerous line
>> $a = 'not found' if not $a;
>> }
>> else
>> {
>> $a = 'invalid perldoc name';
>> }
>> }
>> print header(), start_html();
>> print start_form(), p('Type name of perldoc'),
>> p(textfield(-name=>'docname')),
>> p(submit(-name=>'display')),
>> end_form();
>> print pre($a), end_html();
>> -------------------------------------------
>> me> ./testcgi.pl
>
> Right... you are not passing any value for docname, so the undef that
> CGI.pm gives you is not tainted. With
>
> #!/usr/bin/perl -T
>
> use strict;
> use warnings;
>
> use CGI qw/:standard/;
>
> $ENV{PATH} = "/usr/bin:/bin";
>
> my $doc = param 'docname';
> my $pod = `perldoc $doc`;
> print $pod;
>
> __END__
>
> I get
>
> ~% ./cgitaint docname=open
> Insecure dependency in `` while running with -T switch at ./cgitaint
> line 11.
>
> as expected. If I add
>
> $doc =~ /^([\w:]+)$/ ? $doc = $1 : die "Invalid perldoc name";
>
> in the obvious place I get instead the docs for open.pm.
>
>> Is that correct that Perl will not pick up a taint problem in this
>> case?
>
> No, it is not correct... do you have an example where this happens?
>
> Ben
>
Thanks for examples and advice. I found when I was at work today when I
tried to access my script via the web it would not run. It turns out it
was because of the -T. When I got home and removed it, it worked fine
again.
wana
------------------------------
Date: 8 Nov 2004 03:14:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: an original perldoc viewer
Message-Id: <Xns959AE240AB5E1asu1cornelledu@132.236.56.8>
wana <ioneabu@yahoo.com> wrote in news:10otm79211him89@news.supernews.com:
> Thanks for examples and advice. I found when I was at work today when I
> tried to access my script via the web it would not run. It turns out it
> was because of the -T. When I got home and removed it, it worked fine
> again.
If you don't mind me asking, why did you remove -T instead of fixing the
insecure dependency?
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Mon, 08 Nov 2004 09:00:47 +0800
From: Benjamin Khoo <benkhoo@copperblue.per.sg>
Subject: Re: Binary files in PERL?
Message-Id: <pan.2004.11.08.01.00.47.651047@copperblue.per.sg>
On Sun, 07 Nov 2004 16:08:19 +0000, Ben Morrow wrote:
>
> Quoth "Jürgen Exner" <jurgenex@hotmail.com>:
>> Benjamin Khoo wrote:
>> > i would like to find out how to write a binary file in PERL
>> >
>> > most of the readme and tutorial online only deal with writing ASCII
>> > files.
>>
>> Are you really on an OS that differentiates between binary and text files?
>
> As of 5.8 Perl makes that difference regardless of OS. However, on some
> OSen it defaults to binary and on some to a sort-of mixed text and
> binary mode that is almost certainly completely useless... :)
>
> Ben
hi Ben..
i work on linux.. does that make a difference if it is binary or ascii?
does that mean that using "binmode" might not give me a binary file as
expected?
thanks lots
--
bENJAMIN kHOO
qIU wENDA
http://www.copperblue.per.sg
------------------------------
Date: 7 Nov 2004 21:47:23 -0800
From: krakle@visto.com (krakle)
Subject: Re: Check POP3 E-mail
Message-Id: <237aaff8.0411072147.1f892f1f@posting.google.com>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message news:<Xns9599B87E93D55asu1cornelledu@132.236.56.8>...
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
> news:2v532rF2hr9bnU1@uni-berlin.de:
>
> > A. Sinan Unur wrote:
> >> Gunnar Hjalmarsson wrote:
> >>> The point I was trying to make is that package variables and
> >>> lexically scoped variables behave differently in this respect.
> >>> However, see Brian's message in this thread. Even if I haven't seen
> >>> file scoped lexicals retain their values, I trust that Brian knows
> >>> what he is talking about.
> >>
> >> Gunnar,
> >>
> >> You were correct. What krakle is krakling about is summarized here:
> >>
> >> http://perl.apache.org/docs/1.0/guide/porting.html#Exposing_Apache__Re
> >> gistry_secrets
> >
> > To me, that rather confirms that brian was correct. The handler
> > subroutine, seemingly top level subroutines behaving as nested ditto,
> > etc...
> >
> > I for one learned from this exchange of messages that *really* file
> > scoped lexicals, i.e. top level lexicals in programs that are run
> > under variants of mod_perl that do not make use of any "handler
> > subroutine", retain their values. I did not know that before.
>
> OK. I misunderstood your earlier statement then. Of course, Brian is
> correct. I am re-reading the thread, and it seems like I lost track of
> who was saying what at one point.
>
> My main argument was with the statement that krakle made regarding the
> necessity of resetting package lexicals. That necessity only arises from
> when good programming discipline is not followed, IMHO.
>
>
> Sinan.
mod_perl is my primary use for the web. In the example I gave it would
retain the values from the previous session.
------------------------------
Date: Mon, 8 Nov 2004 05:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 5.22: How do I randomly update a binary file?
Message-Id: <cmmum6$fdk$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
5.22: How do I randomly update a binary file?
If you're just trying to patch a binary, in many cases something as
simple as this works:
perl -i -pe 's{window manager}{window mangler}g' /usr/bin/emacs
However, if you have fixed sized records, then you might do something
more like this:
$RECSIZE = 220; # size of record, in bytes
$recno = 37; # which record to update
open(FH, "+<somewhere") || die "can't update somewhere: $!";
seek(FH, $recno * $RECSIZE, 0);
read(FH, $record, $RECSIZE) == $RECSIZE || die "can't read record $recno: $!";
# munge the record
seek(FH, -$RECSIZE, 1);
print FH $record;
close FH;
Locking and error checking are left as an exercise for the reader. Don't
forget them or you'll be quite sorry.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Sun, 7 Nov 2004 23:35:33 -0600
From: "Jerry Preston" <g-preston1@ti.com>
Subject: Firefox broswer staring Perl CGI
Message-Id: <cmn0j5$sil$1@home.itg.ti.com>
I just checked out some of my Perl CGI scripts that work fine using IE and
Netscape and I find that Firefox is lost or I am. I start my scripts with
the following:
print $query->header();
print $query->start_html( -title => "$main_title By Jerry Preston",
);
print $query->startform( -name => 'update_form',
-method => 'POST',
);
When I do a view page source the following starts the code:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
What am I missing?
Thanks,
Jerry
------------------------------
Date: 8 Nov 2004 06:55:04 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Firefox broswer staring Perl CGI
Message-Id: <Xns959B95662B83castleamber@130.133.1.4>
Jerry Preston wrote:
> I just checked out some of my Perl CGI scripts that work fine using IE
> and Netscape and I find that Firefox is lost or I am. I start my
> scripts with the following:
>
> print $query->header();
^^^^ defaults to XHTML
> <?xml version="1.0" encoding="iso-8859-1"?>
> <!DOCTYPE html
> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
^^^^^
> What am I missing?
-no_xhtml
By default, CGI.pm versions 2.69 and higher emit XHTML
(http://www.w3.org/TR/xhtml1/). The -no_xhtml pragma disables this
feature.
Hence:
use CGI qw/:standard -no_xhtml/;
or use
my $cgi = new CGI;
print $cgi->header( 'text/html' );
I recommend calling the thingy $cgi instead of $query, printing html to
a query sounds odd to me.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 08 Nov 2004 05:11:05 -0000
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Problem with cp in system call running Mac OS X
Message-Id: <slrncotvoi.ulo.tim@vegeta.saiyix>
Tom McDonough <tam3x3@yahoo.com> wrote:
> I'm writing a back up script and want to put all files in directory
> (MRIS) which are not a directory in their own right into a temporary
> directory (TEMP).
perldoc File::Copy
Tim Hammerquist
------------------------------
Date: Mon, 8 Nov 2004 05:52:55 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <cmn1jn$26af$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Sisyphus
<kalinaubears@iinet.net.au>], who wrote in article <418c2f26$0$6552$5a62ac22@per-qv1-newsreader-01.iinet.net.au>:
> NEWSV() creates the string of the desired length - so, unless I'm
> missing the point, there's no need for SvGROW().
People usually try to avoid it since it is not documented. Fat chance
that it will suddently go, though...
> SvPOK_on(outsv);
> SvCUR_set(outsv, len);
> return outsv;
This is not enough.
*SvEND(outsv) = 0; /* Terminate by \0 */
(otherwise calling Perl functions which pass the guy to syscalls will
fail).
Hope this helps,
Ilya
------------------------------
Date: Mon, 08 Nov 2004 06:34:55 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <418f14e0$0$6553$5a62ac22@per-qv1-newsreader-01.iinet.net.au>
Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to
> Sisyphus
> <kalinaubears@iinet.net.au>], who wrote in article <418c2f26$0$6552$5a62ac22@per-qv1-newsreader-01.iinet.net.au>:
>
>
>>NEWSV() creates the string of the desired length - so, unless I'm
>>missing the point, there's no need for SvGROW().
>
>
> People usually try to avoid it since it is not documented. Fat chance
> that it will suddently go, though...
>
>
>> SvPOK_on(outsv);
>> SvCUR_set(outsv, len);
>> return outsv;
>
>
> This is not enough.
>
> *SvEND(outsv) = 0; /* Terminate by \0 */
>
Aahh!! I had done a Devel::Peek::Dump of the various return values and
noticed that the \0 was missing - though CUR and LEN were set correctly.
I couldn't work out how to remedy that. Every successful attempt to add
the \0 seemed to screw up either LEN or CUR (or both). Now I know how to
achieve it. Thanks Ilya.
So the code finally looks like this:
SV * fastest () {
SV * outsv;
int i;
int len = 20000;
outsv = NEWSV(0, len);
srand (time ((time_t) NULL));
for (i = 0; i < len; i ++)
SvPVX(outsv)[i] = rand() % 256;
SvPOK_on(outsv);
SvCUR_set(outsv, len);
*SvEND(outsv) = 0;
return outsv;
}
Which is slightly (negligibly) *slower* than the first code that I
posted (which doubles up on the string buffers).
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: Mon, 08 Nov 2004 03:54:13 GMT
From: "Madra Rua" <madra@rua.net>
Subject: Spam-free Mailto.pl or similar prog?
Message-Id: <F5Cjd.8469$O11.1837@newsread3.news.pas.earthlink.net>
Greetings Gurus.
Excuse the dated material. I have been away from scripting for about 6 years
now and it's very rusty. My old mailto.pl script will not work on iPower's
web hosting site. I searched for a replacement and found the interesting web
site below. Does anyone know what the latest situation is and do they have a
complete mailto.pl with redirection. I believe the iPower site is Unix or a
variant of it.
Thanks for any info.
MR
JamesThornton.com Software Redirect mailto:
Redirect mailto: for Spam Prevention
Summary: Prevent e-mail siphons from harvesting your
e-mail addresses by separating the address from the Web page while still
providing a way for users to click a link and have it open their local
mailer.
I hate spam almost as much as I hate city traffic so I don't use
mailto: links on my website. If you don't know the problem with mailto:
links, read Why No mailto?, by Jakob Nielsen.
Several years ago, I thought of using mailto redirects to reduce spam
by separating e-mail addresses from Web pages while still providing a way
for users to click an e-mail address link and have it open their local
mailer. Instead of using a mailto: link, I use a script that redirects to a
mailto: URI, similar to how you would redirect to a Web page (for more
complete protection, combine a mailto redirect with a Graphic@):
HTML Code Rendered Link
Normal mailto: <a href="mailto:fakeuser@electricspeed.com">Fake
User</a> Fake User
Redirect mailto: <a
href="/email/?u=james&d=electricpspeed.com">James Thornton</a> James
Thornton
Note: Do NOT send e-mail to fakeuser@electricspeed.com, it is a
spamtrap.
Upon a mailto: redirect, IE 5.5+ and Mozilla 5.0+ browsers may change
the browser window to a blank page as it opens the e-mail software -- Opera
and older versions of Netscape and IE handle the mailto: redirect without
drama. Regardless, hitting the back button returns you to the page that you
were on. Also, Salvatore Previti came up with a solution to circument this
issue by including an iframe and setting it as the target of the
redirect-mailto hyperlink. While not all browsers support iframes, the newer
browsers do, and these are the browsers with the issue. I have included an
iframe example in the OpenACS example located in "Graphic @ for Spam
Prevention".
Here's some example code:
Perl
#!/usr/bin/perl -w
# redirect-mailto.pl
use CGI qw(:cgi);
$user = param("u");
$domain = param("d");
print redirect( -URL => "mailto:$user\@$domain" );
OpenACS
AOLserver needs this patch to nsd/return.c; otherwise, it includes the
mailto: link in the server response.
# redirect-mailto.tcl
set_form_variables
ns_returnredirect "mailto:${u}@${d}"
PHP
<?php
// redirect-mailto.php
header("Location: mailto:$_GET[u]@$_GET[d]");
?>
ColdFusion
<!--- redirect-mailto.cfm --->
<cflocation url="mailto:#URL.u@#URL.d#">
ASP
<%
'redirect-mailto.asp
response.redirect("mailto:" & Request.QueryString("u") & "@" &
Request.QueryString("d"))
%>
Place this script in a directory such as /email, and for extra
protection, put the /email path in your robots.txt file to exclude obedient
robots from crawling it and grabbing the output of the link. You could even
include some code that compares the user agent to those listed in
http://www.robotstxt.org/wc/active/all.txt, and if it is a robot, return
nothing.
begin 666 arrow2.gif
M1TE&.#EA# `)`)'_``$!`L# P*2DS61D?2'Y! $```$`+ `````,``D`0 (7
?C"^GFCH`HVP.TO7 =6/AN!F9Y@5#=Q0`.Z:<00(`.P``
`
end
------------------------------
Date: 8 Nov 2004 04:10:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Spam-free Mailto.pl or similar prog?
Message-Id: <Xns959AEBCF31CC3asu1cornelledu@132.236.56.8>
"Madra Rua" <madra@rua.net> wrote in
news:F5Cjd.8469$O11.1837@newsread3.news.pas.earthlink.net:
> Greetings Gurus.
Oh-oh!
> Excuse the dated material.
Which material? Do you mean the binary attachment? Don't post binary
attachments.
> I have been away from scripting for about 6 years
Why not keep it that way?
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Mon, 08 Nov 2004 05:03:51 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: sub refs in qq strings
Message-Id: <X6Djd.8350$Gm6.804@newsread3.news.atl.earthlink.net>
I know I can embed a sub in a interpolated string:
sub getThis{
return ' something to return ';
}
my $content=qq{
Embedded sub here:
@{[getThis]}
After embed.
};
Can I embed a sub ref also? I'm getting kind of fond of dispatch tables.
Jeff
------------------------------
Date: Mon, 08 Nov 2004 05:23:11 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: sub refs in qq strings
Message-Id: <x7ekj4ncch.fsf@mail.sysarch.com>
>>>>> "JT" == Jeff Thies <jeff@spamalanadingong.com> writes:
JT> I know I can embed a sub in a interpolated string:
JT> sub getThis{
JT> return ' something to return ';
JT> }
JT> my $content=qq{
JT> Embedded sub here:
JT> @{[getThis]}
JT> After embed.
JT> };
JT> Can I embed a sub ref also? I'm getting kind of fond of dispatch tables.
what happens to refs when interpolated in strings? they get strigified
and those strings cannot be converted back to the refs. so what are
really looking to do? dispatch tables don't stringify refs. there are
useful cases where stringifying refs is useful. some odd modules (i
think class::classless) blesses refs into the class named by the
stringified ref. this allows each object to be its own (guaranteed
unique) class. another technique i use is when you need to track
all of a set of objects. this could be a class that needs access to all
of its instances or a way to manage a set of active objects (i use it
for a select loop to manage the active event objects for each event
type).
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: 8 Nov 2004 05:30:32 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: sub refs in qq strings
Message-Id: <Xns959B52EA887Dasu1cornelledu@132.236.56.8>
Jeff Thies <jeff@spamalanadingong.com> wrote in news:X6Djd.8350$Gm6.804
@newsread3.news.atl.earthlink.net:
> I know I can embed a sub in a interpolated string:
>
> sub getThis{
> return ' something to return ';
> }
Please indent your code properly when posting in a public forum.
> my $content=qq{
> Embedded sub here:
> @{[getThis]}
>
> After embed.
> };
Do you really understand what is happening here? Strictly speaking, you
are not embedding anything. The array dereference is being interpolated
into the string. It is just that the resultant array only has one
element, the return value of the getThis sub (hate the mixedCase naming
scheme, btw).
> Can I embed a sub ref also? I'm getting kind of fond of dispatch
> tables.
I am not sure what dispatch tables have to do with anything here. But why
not dereference the subref.
use strict;
use warnings;
my $subref = sub {
return 'Ta da!';
};
my $content = qq{Here it is what I say: @{[ $subref->() ]}\n};
print $content;
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: 8 Nov 2004 07:10:36 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: sub refs in qq strings
Message-Id: <Xns959BBF729F59castleamber@130.133.1.4>
Jeff Thies wrote:
> Can I embed a sub ref also? I'm getting kind of fond of dispatch tables.
my %dispatch_table = (
foo => \&foo,
bar => \&bar,
);
my $func = $dispatch_table{ $what };
if ( defined $func ) {
$func->( ..... );
} else {
die "foo bar";
}
sub foo....
sub bar....
I don't get the interpolation thingy.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sun, 7 Nov 2004 17:26:47 -0800
From: "news.west.cox.net" <sean.berry2@cox.net>
Subject: Re: Upload meter for a CGI perl script
Message-Id: <RWzjd.234982$a85.64563@fed1read04>
> I am not an expert, but I was under the impression that the webserver
> (apache or whatever) waits until the transfer has been completed before
> then running the CGI script. A way to test this would be to be to record
> when the script was started.
You may be right. I do not know the ins and outs of it all. However, when
I start an upload of a 10 meg file through a perl script using CGI.pm, I can
see a file named CGItemp$sequence - where $sequence is a four digit number -
being written to in /usr/tmp. As I do ls -lrt's I can see the file growing
in size. I also have a little program that, given the four digit number,
displays the file size every two seconds.
I just need to be able to get this four digit number. I can see in CGI.pm
where it is being created, but it uses a random during generation so it
would not be possible to get the same number by doing a similar algorithm.
What I need is the ability to get the number of $seqno CGI.pm.
Help is greatly appreciated.
------------------------------
Date: Mon, 08 Nov 2004 02:33:26 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: Upload meter for a CGI perl script
Message-Id: <cmmlth$mua$1@gemini.csx.cam.ac.uk>
news.west.cox.net wrote:
>>I am not an expert, but I was under the impression that the webserver
>>(apache or whatever) waits until the transfer has been completed before
>>then running the CGI script. A way to test this would be to be to record
>>when the script was started.
>
>
> You may be right. I do not know the ins and outs of it all. However, when
> I start an upload of a 10 meg file through a perl script using CGI.pm, I can
> see a file named CGItemp$sequence - where $sequence is a four digit number -
> being written to in /usr/tmp. As I do ls -lrt's I can see the file growing
> in size. I also have a little program that, given the four digit number,
> displays the file size every two seconds.
>
> I just need to be able to get this four digit number. I can see in CGI.pm
> where it is being created, but it uses a random during generation so it
> would not be possible to get the same number by doing a similar algorithm.
> What I need is the ability to get the number of $seqno CGI.pm.
>
> Help is greatly appreciated.
>
I don't suppose you're able to guess it from the time of the file
creation? Depends how often this is used, I guess...
If not, I suggest you investigate whether the Perl script is actually
running at the time of the upload. If it isn't, you'd probably be better
off asking in an apache(/or other webserver) newsgroup.
------------------------------
Date: Sun, 7 Nov 2004 19:04:18 -0800
From: "news.west.cox.net" <sean.berry2@cox.net>
Subject: Re: Upload meter for a CGI perl script
Message-Id: <gmBjd.235956$a85.215716@fed1read04>
"Stuart Moore" <usenet_05_08_2004@stuartmoore.org.uk> wrote in message
news:cmmlth$mua$1@gemini.csx.cam.ac.uk...
> news.west.cox.net wrote:
>
>>>I am not an expert, but I was under the impression that the webserver
>>>(apache or whatever) waits until the transfer has been completed before
>>>then running the CGI script. A way to test this would be to be to record
>>>when the script was started.
>>
>>
>> You may be right. I do not know the ins and outs of it all. However,
>> when I start an upload of a 10 meg file through a perl script using
>> CGI.pm, I can see a file named CGItemp$sequence - where $sequence is a
>> four digit number - being written to in /usr/tmp. As I do ls -lrt's I
>> can see the file growing in size. I also have a little program that,
>> given the four digit number, displays the file size every two seconds.
>>
>> I just need to be able to get this four digit number. I can see in
>> CGI.pm where it is being created, but it uses a random during generation
>> so it would not be possible to get the same number by doing a similar
>> algorithm. What I need is the ability to get the number of $seqno CGI.pm.
>>
>> Help is greatly appreciated.
>>
>
> I don't suppose you're able to guess it from the time of the file
> creation? Depends how often this is used, I guess...
>
> If not, I suggest you investigate whether the Perl script is actually
> running at the time of the upload. If it isn't, you'd probably be better
> off asking in an apache(/or other webserver) newsgroup.
I am fairly certain it is running during the upload. In CGI.pm I can see
...
# choose a relatively unpredictable tmpfile sequence number
my $seqno = unpack("%16C*",join('',localtime,values %ENV));
for (my $cnt=10;$cnt>0;$cnt--) {
next unless $tmpfile = new CGITempFile($seqno);
$tmp = $tmpfile->as_string;
last if defined($filehandle =
Fh->new($filename,$tmp,$PRIVATE_TEMPFILES));
$seqno += int rand(100);
}
Then, later on I see...
last if ! -f ($filename =
sprintf("${TMPDIRECTORY}${SL}CGItemp%d",$sequence++));
".../CGItemo%d", $sequence++
Then, in my /usr/tmp dir I see files with names like CGItemp1234,
CGItemp5678, etc.
So, based on that, it seems like CGI.pm is running during the upload.
I just need to get the $sequence var.
------------------------------
Date: Sun, 7 Nov 2004 17:24:48 -0600
From: Ryan Thompson <a@ry.ca>
Subject: Re: Using $SIG{"ALRM"} assignment inside a subroutine ...
Message-Id: <20041107171347.M20279@coyote>
torahul@gmail.com wrote to :
> Hi,
Hi!
> Wondering what's happening here -- is it a bug or an expected behavior
> from perl ? I am trying to set SIGALRM handle from within a
> subroutine; surprisingly it executes the handler rotine soon I assign
> to SIG{"ALRM"}, even I haven't set any alarm!
> Following perl code :
> ----------------- Start of Script -----------------
> #!/usr/local/bin/perl
Please use warnings and strict. This problem almost solved itself!
Among other problems:
> kill ("KILL", $pid);
> }
>
> sub s_sub1 {
> local (@args) = @_;
>
> print ("Setting alarm routine to s_alarm_handler\n");
> $SIG{"ALRM"} = s_alarm_handler;
The above line is the problem. You're setting the value of $SIG{"ALRM"}
to the *return of* s_alarm_handler. It has nothing to do with signal
processing. You need to pass in a *reference* to the subroutine you want
called, like so:
$SIG{"ALRM"} = \&s_alarm_handler;
The actual warning generated is:
You need to quote "s_alarm_handler" at ./sig.pl line 12.
where line 12 is the $SIG{"ALRM"} = s_alarm_handler call.
> If I move SIG{"ALRM"} assignment outside the subroutine, it's working
> as I would expect.
I doubt that, unless you assigned it differently.
See the first page of "perldoc perlipc".
Here's the complete fixed script which runs under -w and strict:
#!/usr/local/bin/perl -w
use strict;
my $pid = 0;
sub s_alarm_handler {
print ("$$ : *** KILLING process(pid=$pid) after timeout\n");
kill ("KILL", $pid);
}
sub s_sub1 {
my (@args) = @_; # You had "local". Anyway, why copy @_?
print ("Setting alarm routine to s_alarm_handler\n");
$SIG{"ALRM"} = \&s_alarm_handler; # sub reference
print ("Alarm routine set to s_alarm_handler\n");
}
s_sub1 ("something"); # No need for & here
It produces the following output:
Setting alarm routine to s_alarm_handler
Alarm routine set to s_alarm_handler
Hope this helps,
- Ryan
--
Ryan Thompson <ryan@sasknow.com>
SaskNow Technologies - http://www.sasknow.com
901-1st Avenue North - Saskatoon, SK - S7K 1Y4
Tel: 306-664-3600 Fax: 306-244-7037 Saskatoon
Toll-Free: 877-727-5669 (877-SASKNOW) North America
------------------------------
Date: Sun, 7 Nov 2004 18:41:25 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Using $SIG{"ALRM"} assignment inside a subroutine ...
Message-Id: <slrncotg5l.2o8.tadmc@magna.augustmail.com>
torahul@gmail.com <torahul@gmail.com> wrote:
> Wondering what's happening here
You are running without "use strict" turned on, so you
deserve any pain that you get.
If you don't like pain, enable strictures on every Perl
program you write.
> -- is it a bug or an expected behavior
> from perl ?
You told perl to _call_ the subroutine, so it calls the subroutine,
just as expected.
> I am trying to set SIGALRM handle from within a
> subroutine; surprisingly it executes the handler rotine soon I assign
> to SIG{"ALRM"},
> $SIG{"ALRM"} = s_alarm_handler;
^^ ^^ where's the quotes
You should put quotes around your strings.
"use strict" would have saved you from yourself here!
> &s_sub1 ("something");
s_sub1 ("something");
See perldoc perlsub for why the 2nd way is usually Much Better
than the first way.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 7375
***************************************