[16297] in Perl-Users-Digest
Perl-Users Digest, Issue: 3709 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 18 09:27:48 2000
Date: Tue, 18 Jul 2000 06:27:37 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963926857-v9-i3709@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 18 Jul 2000 Volume: 9 Number: 3709
Today's topics:
Bottleneck? Array or writing - neither? (Eric)
Re: Bottleneck? Array or writing - neither? (Keith Calvert Ivey)
Re: Bottleneck? Array or writing - neither? (Eric)
Re: Called executable can't access net drive ()
Can i 'logout' a protected directory? (Nivel33)
CGI problem, newbie, code follows.... (Russell Smallwood)
Re: CGI problem, newbie, code follows.... (Kiel Stirling)
Re: CGI-to-NT service communication..... (Greg Treece)
Re: CGI-to-NT service communication..... (Greg Treece)
CGI.pl problem with checkbox (Tony Balazs)
CGI: How do I set/get cookies ? ()
Re: Checking the size of an E-mail... (jb)
chop vs. chomp (was: Read a file into a hash ?) (Ilmari Karonen)
Re: clear query string (Jonathan Stowe)
closing read-only filehandles [was: Read a file into a (jason)
Re: closing read-only filehandles [was: Read a file int <flavell@mail.cern.ch>
Re: closing read-only filehandles [was: Read a file int (Eric Bohlman)
Re: closing read-only filehandles [was: Read a file int (jason)
Re: closing read-only filehandles [was: Read a file int (Larry Rosler)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Jul 2000 01:30:03 GMT
From: esmithNOesSPAM@exeter.com.invalid.bbs@openbazaar.net (Eric)
Subject: Bottleneck? Array or writing - neither?
Message-Id: <3bNaeR$Xzt@openbazaar.net>
**Sorry if this came through twice - I tried remarq's "posting
from e-mail" and it didn't show up all day, so now I'll try via
this little form**
Good day! I am new to perl and absolutely love it - I'm not sure
the last time I've had so much fun - and wow is this fast!
My question that the subject hints at is this:
I have a program that is doing several things, and I tossed in
timers that print to the screen to see where the bottleneck is
since it will sit here nicely and use lots of processor
otherwise without me knowing what stage it has hit.
The first stage it pulls in text from a file (2861742 chars,
527190 words, and 54114 lines) and tosses that into an array.
That works nicely and is not the bottleneck (0.31 CPU seconds on
a dual processor PIII 600 with 256 megs ram - although if you
ask me it is only using one processor - I think NT is bad about
that and forces programs to deal with it on their own - there's
a side question - can you control threads or processors via
Perl - sorry, I'm new).
Next it does a for loop through the array and strips out some
characters (nonword chars and numbers) - this takes 1.66 CPU
seconds - still not the bottleneck.
Then it joins that array into a string - nice and fast at 0.09
CPU s.
After that it goes through from the very end and takes every 4th
character and tosses that into a spot in the array, then chops
of the last letter and continues through that. I thought that's
be the bottleneck - but that is still fast at 8.48 CPU seconds.
Then I sort the array with a simple $a cmp $b and that weighs in
at the heavy 22.44 CPU secs.
And last, but certianly not least, it sits there for over an
hour now where it does many a thing (and this is where I'd love
feedback on ways to speed this up - the rest might not be
perfect, but it is very reasonably fast considering how much it
is going through) - any suggestions (feel free to tell me how
bad my code is - I'm still learning and love feedback - esp the
kind that makes my code faster) would be very much appreciated!
#I'm reading up on hashes now to see if I can use them to make
this faster
my $oldWord = '';
for (@bigArrayOWords)
{
my $testWord = $_;
if ($testWord ne $oldWord)
{
#print $_, "\n";
my $count = grep $_ eq $testWord =>
@bigArrayOWords;
my $step=0;
my $condition=0;
while($condition <= $count)
{
$condition = int(2**$step);
$step++;
}
my $score = $step-1;
if ($score<=0)
{
$score = 0;
}
#output to file
open (TETRAGRAPHS, ">>$tetragraphs") or
die "cannot open TETRAGRAPHS: $!";
print TETRAGRAPHS "$testWord:$count:$score
\n";#ouputs WORD:COUNT:SCORE
close TETRAGRAPHS or die "cannot close
TETRAGRAPHS: $!";
#output to screen
#print "$testWord:$count:$score";#ouputs
WORD:FREQUENCY:SCORE
#print "\n";
}
$oldWord = $testWord;
}
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: 13 Jul 2000 02:30:04 GMT
From: kcivey@cpcug.org.bbs@openbazaar.net (Keith Calvert Ivey)
Subject: Re: Bottleneck? Array or writing - neither?
Message-Id: <3bNcJT$Wq1@openbazaar.net>
Eric <esmithNOesSPAM@exeter.com.invalid> wrote:
>#I'm reading up on hashes now to see if I can use them to make
>this faster
That's definitely what you should be doing. The words "count"
and "unique" should trigger thoughts of hashes.
>my $oldWord = '';
>for (@bigArrayOWords)
>{
> my $testWord = $_;
> if ($testWord ne $oldWord)
When you have a conditional that covers the whole last part of a
loop, it's nicer to reverse the sense of the test and use next:
next if $testWord eq $oldWord;
That way you can avoid indenting the whole rest of the loop.
> {
> #print $_, "\n";
> my $count = grep $_ eq $testWord =>
>@bigArrayOWords;
This is where a lot of your time goes, I'd guess. For every
unique entry in the array, you're looping through the array
again (with grep).
There are some weird things below, but they're probably not
slowing you down much:
> my $step=0;
> my $condition=0;
> while($condition <= $count)
> {
> $condition = int(2**$step);
> $step++;
> }
> my $score = $step-1;
> if ($score<=0)
> {
> $score = 0;
> }
How could $score ever be less than 0? $count is always at least
1; $step starts at 0; so you always go through the while loop at
least once, and $step is always at least 1. And if $score is
equal to 0, there's no need to set it equal to 0.
And what's the int() for? $step is an integer, so 2 ** $step
will be an integer.
Anyway, this whole section can be replaced with one line:
my $score = int(log($count)/log(2)) + 1;
> #output to file
> open (TETRAGRAPHS, ">>$tetragraphs") or
>die "cannot open TETRAGRAPHS: $!";
>
> print TETRAGRAPHS "$testWord:$count:$score
>\n";#ouputs WORD:COUNT:SCORE
>
> close TETRAGRAPHS or die "cannot close
>TETRAGRAPHS: $!";
Here's another big slowdown. You're opening and closing the
file each time through the loop. Open it before the loop and
close it after.
> #output to screen
> #print "$testWord:$count:$score";#ouputs
>WORD:FREQUENCY:SCORE
>
> #print "\n";
> }
> $oldWord = $testWord;
>}
You need to use a hash. You can probably construct it instead
of the array, but I don't know how you're constructing the
array. You can construct the hash from the array (which you
don't need to sort first) like this:
my %count;
++$count{$_} for @bigArrayOWords;
And then just do this instead of everything you've written
above:
open(T, ">>$tetragraphs")
or die "cannot open $tetragraphs: $!";
for (sort keys %count) {
my $score = int(log($count{$_})/log(2)) + 1;
print T "$_:$count{$_}:$score\n";
}
close T or die "cannot close $tetragraphs: $!";
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: 13 Jul 2000 02:50:06 GMT
From: esmithNOesSPAM@exeter.com.invalid.bbs@openbazaar.net (Eric)
Subject: Re: Bottleneck? Array or writing - neither?
Message-Id: <3bNciU$YGU@openbazaar.net>
Thanks for the quick reply Keith - hopefully I can fix this
tonight and run it on
my computer at home (I think it is still running at work right
now)!
>>#I'm reading up on hashes now to see if I can use them to make
this faster
>That's definitely what you should be doing. The words "count"
>and "unique" should trigger thoughts of hashes.
Yeah, I'm a pretty big newbie - not a comp sci guy (I'm sure you
can tell
by the code errs) - but I had just now written up a test on a
small amount
of text, now I'll write it into this big one.
>>my $oldWord = '';
>>for (@bigArrayOWords)
>>{
>>my $testWord = $_;
>>if ($testWord ne $oldWord)
>When you have a conditional that covers the whole last part of
a loop, it's
>nicer to reverse the sense of the test and use next:
>
>next if $testWord eq $oldWord;
>
>That way you can avoid indenting the whole rest of the loop.
awesome! thanks - I don't know a lot fo this stuff that is
probably common
sense to you guys - I'm learning though and having a blast!
>>{
>>#print $_, "\n";
>>my $count = grep $_ eq $testWord =>
>>@bigArrayOWords;
>This is where a lot of your time goes, I'd guess. For every
unique entry in the
>array, you're looping through the array again (with grep).
ouch! I grabbed that code off of someone's post in a newsgroup
(likely
this one) and I didn't really think it through since it seemed
fast enough in tests
(obviously much smaller tests)
>There are some weird things below, but they're probably not
slowing you
>down much:
these are scoring tests
>>my $step=0;
>>my $condition=0;
>>while($condition <= $count)
>>{
>>$condition = int(2**$step);
>>$step++;
>>}
>>my $score = $step-1;
>>if ($score<=0)
>>{
>>$score = 0;
>>}
>How could $score ever be less than 0? $count is always at least
1; $step starts
>at 0; so you always go through the while loop at least once,
and $step is always
>at least 1. And if $score is equal to 0, there's no need to set
it equal to 0.
yeah, I guess that was/is dumb. that part was written late at
night and obviously snuck
right by me - no excuse as to why I didn't notice it later on
though - Thanks!
>Anyway, this whole section can be replaced with one line:
>
>my $score = int(log($count)/log(2)) + 1;
great! - I love the one line condensers
>>#output to file
>>open (TETRAGRAPHS, ">>$tetragraphs") or die "cannot open
TETRAGRAPHS: $!";
>>print TETRAGRAPHS "$testWord:$count:$score
>>\n";#ouputs WORD:COUNT:SCORE
>>close TETRAGRAPHS or die "cannot close
>>TETRAGRAPHS: $!";
>Here's another big slowdown. You're opening and closing the
file each time through
>the loop. Open it before the loop and close it after.
hmm, yeah, before I had it as you say and on tests this seemed
to speed it up - obviously
I'm not testing it hard enough prior to the real thing - lesson
learned.
>You need to use a hash. You can probably construct it instead
of the array, but I don't
>know how you're constructing the array. You can construct the
hash from the array
>(which you don't need to sort first) like this:
I'll look into it - the array is huge (over 1,792,911), it looks
like I don't need it though
Thanks so much again for all of your help! I look forward to
seeing more responses -
great way to learn to have someone review your code.
-Eric
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: 12 Jul 2000 17:20:03 GMT
From: aabill@my-deja.com.bbs@openbazaar.net ()
Subject: Re: Called executable can't access net drive
Message-Id: <3bNO43$Uq5@openbazaar.net>
Ok - I found the answer - here's how I did it (with dummy
passwords). Hope it's useful to someone...
$mailprog = "d:\\progs\\mailsend\\mailsend.exe";
$recipient = "bill allison";
$subject = "Intranet Suggestion";
$postoffice="\\\\earlston\\data\\msmail\\data";
$bodyfile='d:\\data\\bsw\\cgi-bin\\body.txt';
#delete any existing mapping - send errors to nul
#map m: to the location of the postoffice - m: is mailsend's
#default location to look in. Hide response in nul.
#call mailsend - that this works tells me that mappings are persistent
#across perl system() calls - handy! I will use a log file instead of
#nul here (honest). Oh and the user who is running the web server must
#of course have rights to the Netware resources.
system('net use m: /DELETE >nul');
system('net use m: '.$postoffice.' 12345678 /USER:admin >nul');
system ($mailprog.' -fadmin -p12345678 -s'.$subject.' -t'.$recipient.' -
i'.$bodyfile >nul);
--------------------------------------------------------------------
In article <8kfoas$vcf$1@nnrp1.deja.com>,
aabill@my-deja.com wrote:
> Platform:
> Intranet on IIS 4.0 on NT Server 4.0 SP6a with Novell client
> ActivePerl 5 Build 613
>
> Problem:
> I need intranet users to be able to e-mail suggestions to a particular
> MSMail account. I can't use a mailto: in the client html because IE
> won't parse the mailto:'s subject field (and Netscape is not an option
> for us) and a subject field is needed to tell the recipient which of
> two mail forms on the intranet was the source.
>
> So I've used a client mail form to call a perl script to send mail to
> the MSMail Post Office on our Netware 5 server. The script does a
system
> () to call a "mailsend" executable with parameters, one of which is
the
> network location of the post office - in this case
> //earlston/data/msmail/data. The script works fine from the command
> line but not when invoked from a browser.
>
> I have realised that although the Netware box is logged on and visible
> from the NT box, it is not visible to the script when called from the
> browser. I have tried creating a virtual directory mapped to the Post
> Office directory to get round this but although it creates apparently
> normally, and it's contents are visible in the mamngement console, the
> icon is a red "Error" and the approach has not worked.
>
> I've read hundreds of FAQs and searched all the postings - if someone
> does have an answer I will be very, very grateful.
>
> Thanks in anticipation,
> Bill Allison
> BSW Timber plc
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 17 Jul 2000 11:00:01 GMT
From: nivel33@hotmail.com.bbs@openbazaar.net (Nivel33)
Subject: Can i 'logout' a protected directory?
Message-Id: <3bR9X1$X5l@openbazaar.net>
When i protected a directory and the user is identificated, I need the
'change login' option
If i send a 'logout' (HTTP Header) i can't ask the new login & password
Ex.
Input user :
www.onedomain.com/protecteddir/
[Login : xxxx]
[Passwd : xxx ]
The user see the page and wants to change login to see as another user.
Press the [logout button] ( but the browser have this data in your cache)
the system cgi send the HTTP Header -> (Invalid password) but the login and
password it doesn´t work again
sorry my english
------------------------------
Date: 14 Jul 2000 21:40:02 GMT
From: rsmallwood@mindspring.com.bbs@openbazaar.net (Russell Smallwood)
Subject: CGI problem, newbie, code follows....
Message-Id: <3bP9f5$VmC@openbazaar.net>
My question is very simple, when I run this:
use CGI;
$wp=new CGI;
$name=$wp->param ('name');
$organization=$wp->param ('organization');
$workphone=$wp->param ('workphone');
$fax=$wp->param ('fax');
$URL=$wp->param ('URL');
$email=$wp->param ('email');
$title=$wp->param ('titile');
print >>EOF;
<html>
<head>
<title>Whoops</title>
</head>
<body topmargin='0' leftmargin='0'>
<p><img border='0' src='images/smallheader.JPG' width='527' height='61'>
</p>
<p><b><font face='Arial' size='5'> Whoops..</font></b></p>
<p><font face='Arial'> Please fill out the form
entirely
before hitting the submit button.<br>
You
may use
your browser\'s <b>"back"</b> button to continue without
loosing your
work.</font></p>
<p> </p>
</body>
</html>
EOF
I get this
CGI Error
The specified CGI application misbehaved by not returning a complete set
of HTTP headers. The headers it did return are:
Bareword found where operator expected at D:\Maple\wwwroot\scripts
\webimportdemo.pl line 22, near "
Line 22 is
<title>Whoops</title>
If this is a dumb question, please point me in the right direction,
perhaps some recommended reading. I've read the official guide to
Programming with CGI.pm but as I am not an HTML programmer I was hoping
to create some mockups in Front Page, and cut and paste them into my
scripts using print >>. Perhaps this is a bad idea? Weird thing is
that I did this on a couple of other pages and they work fine. I've
compared them to this and they seem to be identical.
Russell
Russell
------------------------------
Date: 15 Jul 2000 01:00:01 GMT
From: taboo@doofa.net.bbs@openbazaar.net (Kiel Stirling)
Subject: Re: CGI problem, newbie, code follows....
Message-Id: <3bPF31$YWO@openbazaar.net>
rsmallwood@mindspring.com (Russell Smallwood) wrote:
>My question is very simple, when I run this:
>
>
>use CGI;
>
>$wp=new CGI;
>
>$name=$wp->param ('name');
>$organization=$wp->param ('organization');
>$workphone=$wp->param ('workphone');
>$fax=$wp->param ('fax');
>$URL=$wp->param ('URL');
>$email=$wp->param ('email');
>$title=$wp->param ('titile');
>
> print >>EOF;
>
><html>
>
><head>
>
><title>Whoops</title>
></head>
>
><body topmargin='0' leftmargin='0'>
>
><p><img border='0' src='images/smallheader.JPG' width='527' height='61'>
></p>
><p><b><font face='Arial' size='5'> Whoops..</font></b></p>
><p><font face='Arial'> Please fill out the form
>entirely
>before hitting the submit button.<br>
> You
>may use
>your browser\'s <b>"back"</b> button to continue without
>loosing your
>work.</font></p>
><p> </p>
>
></body>
>
></html>
>
>EOF
>
>I get this
>
>CGI Error
>The specified CGI application misbehaved by not returning a complete set
>of HTTP headers. The headers it did return are:
>
>
>Bareword found where operator expected at D:\Maple\wwwroot\scripts
>\webimportdemo.pl line 22, near "
>
>
>Line 22 is
>
><title>Whoops</title>
>
>If this is a dumb question, please point me in the right direction,
>perhaps some recommended reading. I've read the official guide to
>Programming with CGI.pm but as I am not an HTML programmer I was hoping
>to create some mockups in Front Page, and cut and paste them into my
>scripts using print >>. Perhaps this is a bad idea? Weird thing is
>that I did this on a couple of other pages and they work fine. I've
>compared them to this and they seem to be identical.
>
>Russell
I think you need to print the Content type to the browser
try above your html printing the following
print "Content-Type: text/html\n\n";
This must end in two newlines (\n\n)
Kiel Stirling
------------------------------
Date: 12 Jul 2000 13:00:03 GMT
From: gtreece@vhbtech.com.bbs@openbazaar.net (Greg Treece)
Subject: Re: CGI-to-NT service communication.....
Message-Id: <3bNHF3$Z8G@openbazaar.net>
Thanks for your response.
The service is straight from the book "Visual C++ 5 Unleashed", chapter 52
"Writing A Windows NT Service" and uses straight-up, off-the-shelf socket
techniques:
%%--snip--%%
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == INVALID_SOCKET) goto cleanup;
sin.sin_family = AF_INET;
sin.sin_port = SVCPORT;
sin.sin_addr.s_addr = 0;
if (bind(sockfd, (LPSOCKADDR)&sin, sizeof(sin))) goto cleanup;
if (listen(sockfd, 5) < 0) goto cleanup;
if (!ReportStatusToSCMgr(SERVICE_RUNNING, NO_ERROR, 0))
goto cleanup;
while (1)
{
unsigned long ul;
SOCKET newsockfd = accept(sockfd, NULL, NULL);
if (g_bStop)
{
if (newsockfd != INVALID_SOCKET) closesocket(newsockfd);
break;
}
if (newsockfd == INVALID_SOCKET)
{
if (bDebug) cout << "Socket error " << WSAGetLastError() << endl;
}
else
{
struct linger l;
l.l_onoff = TRUE;
l.l_linger = 1;
setsockopt(newsockfd, SOL_SOCKET, SO_LINGER, (LPSTR)&l, sizeof(l));
CSlot *pSlot = new CSlot(pSvc, newsockfd, id++);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread, pSlot, 0, &ul);
}
}
%%--snip--%%
The client is in PERL as follows:
%%--snip--%%
use IO::Socket;
$socket = IO::Socket::INET->new
(
PeerAddr => $SvcHost,
PeerPort => $SvcPort,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not create client.\n";
print $socket $cmd;
%%--snip--%%
I believe that the real problem is NT security based because I can run the
PERL client manually
with success; it dies only when launched as a CGI script from APACHE with
the error "Could not create client.".
kbcafe@my-deja.com wrote:
> If you are using TCP/IP or UDP/IP sockets, then there should not be any
> interprocess security issues.
> --
> Randy Charles Morin [MVP] - http://www.kbcafe.com/
> Author of "Programming Windows Services"
> http://www.amazon.com/exec/obidos/ASIN/047138576X/kbcafe
>
> In article
> <56CEC26EFF90B73F.82AEAF49592F5301.5CCB9E915F9DB48F@lp.airnews.net>,
> Greg Treece <gtreece@vhbtech.com> wrote:
> > I am trying to feed some information from a cgi program (Apache) to an
> > NT service via a socket and
> > my perl script cannot open its socket connection. This works when run
> > from the command
> > line. Are there interprocess security settings somewhere to make this
> > happen?
> >
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: 12 Jul 2000 13:00:03 GMT
From: gtreece@vhbtech.com.bbs@openbazaar.net (Greg Treece)
Subject: Re: CGI-to-NT service communication.....
Message-Id: <3bNHF4$ZCH@openbazaar.net>
Thanks for your response.
The service is straight from the book "Visual C++ 5 Unleashed", chapter 52
"Writing A Windows NT Service" and uses straight-up, off-the-shelf socket
techniques:
%%--snip--%%
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == INVALID_SOCKET) goto cleanup;
sin.sin_family = AF_INET;
sin.sin_port = SVCPORT;
sin.sin_addr.s_addr = 0;
if (bind(sockfd, (LPSOCKADDR)&sin, sizeof(sin))) goto cleanup;
if (listen(sockfd, 5) < 0) goto cleanup;
if (!ReportStatusToSCMgr(SERVICE_RUNNING, NO_ERROR, 0))
goto cleanup;
while (1)
{
unsigned long ul;
SOCKET newsockfd = accept(sockfd, NULL, NULL);
if (g_bStop)
{
if (newsockfd != INVALID_SOCKET) closesocket(newsockfd);
break;
}
if (newsockfd == INVALID_SOCKET)
{
if (bDebug) cout << "Socket error " << WSAGetLastError() << endl;
}
else
{
struct linger l;
l.l_onoff = TRUE;
l.l_linger = 1;
setsockopt(newsockfd, SOL_SOCKET, SO_LINGER, (LPSTR)&l, sizeof(l));
CSlot *pSlot = new CSlot(pSvc, newsockfd, id++);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread, pSlot, 0, &ul);
}
}
%%--snip--%%
The client is in PERL as follows:
%%--snip--%%
use IO::Socket;
$socket = IO::Socket::INET->new
(
PeerAddr => $SvcHost,
PeerPort => $SvcPort,
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not create client.\n";
print $socket $cmd;
%%--snip--%%
I believe that the real problem is NT security based because I can run the
PERL client manually
with success; it dies only when launched as a CGI script from APACHE with
the error "Could not create client.".
Ha Quach wrote:
> source code may be useful.
> -ha.
>
> Greg Treece wrote:
> >
> > I am trying to feed some information from a cgi program (Apache) to an
> > NT service via a socket and
> > my perl script cannot open its socket connection. This works when run
> > from the command
> > line. Are there interprocess security settings somewhere to make this
> > happen?
------------------------------
Date: Tue, 18 Jul 2000 11:29:20 GMT
From: tbalazs-this-must-go@netcomuk.co.uk (Tony Balazs)
Subject: CGI.pl problem with checkbox
Message-Id: <39743f33.9385874@1.0.0.119>
Apologies if this post doesn't belong in this ng;
I've also posterd to ciwah:
In my CGI I have:
use CGI qw(:standard);
#other stuff
print p(checkbox(-name=>"ref",-value=>"Y",-checked=>0), " Ref: $a");
#other stuff
This is producing as HTML:
<P><INPUT TYPE="checkbox" NAME="ref" VALUE="Y">ref Ref: 100
i.e. there is an extra "ref" being printed before Ref: 100, I guess
the NAME value.
How can I get the output to be:
<P><INPUT TYPE="checkbox" NAME="ref" VALUE="Y"> Ref: 100
?
Thanks for any advice,
Tony
------------------------------
Date: 16 Jul 2000 15:10:03 GMT
From: martho@my-deja.com.bbs@openbazaar.net ()
Subject: CGI: How do I set/get cookies ?
Message-Id: <3bQQXR$UOQ@openbazaar.net>
Hi !
How do I set/get cookies in Perl-CGIs ?
Regards
Martin
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 17 Jul 2000 20:30:10 GMT
From: jbroz@yperite.demon.co.uk.bbs@openbazaar.net (jb)
Subject: Re: Checking the size of an E-mail...
Message-Id: <3bROPY$Vi9@openbazaar.net>
Raphael Pirker wrote:
>
> Thanks! I did come about that far. But the problem is that the e-mail is no
> file! I can read a file, but I didn't figure out how to read in a "couple of
> written bytes". Here's my sendmail code:
>
> open(MAIL,"|$mailprog -t");
>
> print MAIL "To: \"$yourname\" <$admin_recipient>\n";
Use a here document to eliminate all those print statements. Your code
will be cleaner as a result
------------------------------
Date: 18 Jul 2000 07:50:09 GMT
From: iltzu@sci.invalid.bbs@openbazaar.net (Ilmari Karonen)
Subject: chop vs. chomp (was: Read a file into a hash ?)
Message-Id: <3bRgBX$TXW@openbazaar.net>
In article <k8ektozh.fsf@macforce.sumus.dk>, Jakob Schmidt wrote:
>Certainly. But I think I remember that chop is faster (as it would seem
>obvious) so it may still be defended in a cas such as this where the input is
>very disciplined. You may argue of course that the solutions posted in this
>forum serve as general examples as well and ought to be fool proof.
We could indeed argue that - and in fact we frequently do.
We could also argue that any speed difference is totally insignificant
unless the operation is done in a tight loop, and probably even then.
Further, we could argue than any claims about execution speed are next
to worthless unless backed by benchmarks, and that benchmark results
can sometimes be quite surprising:
#!/usr/bin/perl -w
use strict;
use Benchmark;
timethese 1<<(shift||0),
{ chop => '$_ = "\n"x1024; chop while $_;',
chomp => '$_ = "\n"x1024; chomp while $_;',
};
__END__
Benchmark: timing 65536 iterations of chomp, chop...
chomp: 44 wallclock secs (43.74 usr + 0.00 sys = 43.74 CPU)
chop: 51 wallclock secs (50.52 usr + 0.00 sys = 50.52 CPU)
This is perl, version 5.005_03 built for i386-linux
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method." -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: 16 Jul 2000 18:10:08 GMT
From: gellyfish@gellyfish.com.bbs@openbazaar.net (Jonathan Stowe)
Subject: Re: clear query string
Message-Id: <3bQVIc$Vq9@openbazaar.net>
On Fri, 14 Jul 2000 20:52:26 GMT sethipra@wellsfargo.com wrote:
> Hi,
>
> I can delete my query string sent through POST method by saying :
> CGI::delete_all() ;
>
> can you pls tell me a way to clear my query string in GET method so
> that it is not shown in address bar always
>
You can't.
/J\
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: 17 Jul 2000 23:00:02 GMT
From: elephant@squirrelgroup.com.bbs@openbazaar.net (jason)
Subject: closing read-only filehandles [was: Read a file into a hash ?]
Message-Id: <3bRSL2$Vq9@openbazaar.net>
Larry Rosler wrote ..
>Closing a file opened for reading is pointless, unless another process
>or later in this process intends to access it.
I don't really "get" this attitude of not closing read filehandles ..
and I'd appreciate anyone's explanation who supports this practice
Larry's rationale above seems to be that we don't need to do it - so why
do it .. the implication is that we know in advance how our program will
be used
if we all knew every situation that all our code was going to be used in
- then there'd be little reason to do a lot of the things that this
group seems to hold high (including using taint, using HTML::Parser, and
localising special vars)
surely the closing of read filehandles is pro-active programming -
preventing problems that arise from unforseen uses of our code .. the
filehandle is going to be closed at some point - so why not do it
explicitly when we're finished with it
at worst this is self-documenting our usage of that filehandle (ie.
we're finished reading from this filehandle)
at best it's preventing some problem down the track
the only justification I can think of for not closing them is some
keystroke based one .. have I missed something ?
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Tue, 18 Jul 2000 11:43:26 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: closing read-only filehandles [was: Read a file into a hash ?]
Message-Id: <Pine.GHP.4.21.0007181140130.16078-100000@hpplus03.cern.ch>
On Mon, 17 Jul 2000, Larry Rosler wrote:
> I don't remember the subject; I do remember suggesting the solution --
> close the file before unlinking or renaming it!
But on systems that implement file locking, this is going to unlock
the file - and thus let others get at it in the window before it's
actually unlinked/renamed.
cheers
------------------------------
Date: 18 Jul 2000 03:30:04 GMT
From: ebohlman@netcom.com.bbs@openbazaar.net (Eric Bohlman)
Subject: Re: closing read-only filehandles [was: Read a file into a hash ?]
Message-Id: <3bRZMS$XXi@openbazaar.net>
jason (elephant@squirrelgroup.com) wrote:
: surely the closing of read filehandles is pro-active programming -
: preventing problems that arise from unforseen uses of our code .. the
: filehandle is going to be closed at some point - so why not do it
: explicitly when we're finished with it
Didn't we have a thread a few weeks ago where somebody's problem turned
out to be that they were trying to unlink or rename a file on a Win32
system and they couldn't because they still had it open for reading?
------------------------------
Date: 18 Jul 2000 04:00:03 GMT
From: elephant@squirrelgroup.com.bbs@openbazaar.net (jason)
Subject: Re: closing read-only filehandles [was: Read a file into a hash ?]
Message-Id: <3bRaC3$VCJ@openbazaar.net>
Eric Bohlman wrote ..
>jason (elephant@squirrelgroup.com) wrote:
>: surely the closing of read filehandles is pro-active programming -
>: preventing problems that arise from unforseen uses of our code .. the
>: filehandle is going to be closed at some point - so why not do it
>: explicitly when we're finished with it
>
>Didn't we have a thread a few weeks ago where somebody's problem turned
>out to be that they were trying to unlink or rename a file on a Win32
>system and they couldn't because they still had it open for reading?
I didn't catch that one .. I'd be interested to read it - and read why
people still see closing read-only filehandles as pointless
can you remember the subject - or part thereof so I can look it up ?
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: 18 Jul 2000 05:40:04 GMT
From: lr@hpl.hp.com.bbs@openbazaar.net (Larry Rosler)
Subject: Re: closing read-only filehandles [was: Read a file into a hash ?]
Message-Id: <3bRcf4$Wnu@openbazaar.net>
In article <MPG.13de73b7c8a0cdaf9896e4@news>, elephant@squirrelgroup.com
says...
> Eric Bohlman wrote ..
> >jason (elephant@squirrelgroup.com) wrote:
> >: surely the closing of read filehandles is pro-active programming -
> >: preventing problems that arise from unforseen uses of our code .. the
> >: filehandle is going to be closed at some point - so why not do it
> >: explicitly when we're finished with it
> >
> >Didn't we have a thread a few weeks ago where somebody's problem turned
> >out to be that they were trying to unlink or rename a file on a Win32
> >system and they couldn't because they still had it open for reading?
>
> I didn't catch that one .. I'd be interested to read it - and read why
> people still see closing read-only filehandles as pointless
This thread has gone somewhat astray.
Let us define 'pointless' as 'having no operational effect'. It is
indeed pointless to check for success when closing a read-only
filehandle. Whether it is pointless to close the file explicitly
depends on the circumstances of future access, as I said. Evidently
closing the file simply to document that it is no longer being used
might be considered enough 'point' by some.
> can you remember the subject - or part thereof so I can look it up ?
I don't remember the subject; I do remember suggesting the solution --
close the file before unlinking or renaming it!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3709
**************************************