[26365] in Perl-Users-Digest
Perl-Users Digest, Issue: 8537 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 18 14:05:27 2005
Date: Tue, 18 Oct 2005 11:05:06 -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 Tue, 18 Oct 2005 Volume: 10 Number: 8537
Today's topics:
Re: Case Sensitive Regex <no@email.com>
Re: Case Sensitive Regex <joe@inwap.com>
idiom for managing passed arguments? <clarke@n_o_s_p_a_m_hyperformix.com>
Re: idiom for managing passed arguments? <lawrence@hummer.not-here.net>
Re: Microsoft Hatred FAQ <davids@webmaster.com>
Perl Script Question - Working with Directories (Rich Barnes)
where is my text file? <tac@tac.ouch.co.uk>
Re: where is my text file? <tac@tac.ouch.co.uk>
Re: where is my text file? <rvtol+news@isolution.nl>
Re: where is my text file? <glex_no-spam@qwest-spam-no.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 18 Oct 2005 12:03:20 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Case Sensitive Regex
Message-Id: <3rk33pFjq0c2U1@individual.net>
Robert wrote:
> Hello,
>
> I am trying to secure my mailer script from those who might try to hijack it
> by adding "To:" etc fields in the form fields.
> Currently I am using this:
>
> my $name = param('name');
> if ($name =~ /To:/) { &spamattempt; }
> if ($name =~ /to:/) { &spamattempt; }
>
> Basically if the "name" fields contains either an upper or lower case To or
> to the script will direct to a subroutine where the process is terminated.
> This all works fine. My Question ... is there an easier way to write the
> regex above that looks for To:/to: etc? I was thinking maybe it could be
> done with a single regex where is searches for either an upper or lower case
> T or O followed by a : I did some research on regex case sensitivity and
> found that the "i" operator is needed but couldn't make it work. Thanx all
> in advance.
>
> Robert
Case insensitive regexs are very slow. I try to use index where
possible, with a case modifier, which when I last did some benching on
this issue was 6 times faster than a regex on my test machine IIRC.
spamattempt() if (index(lc $name, 'to:') != -1);
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Tue, 18 Oct 2005 04:45:55 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Case Sensitive Regex
Message-Id: <Buadnbjw8LEefcneRVn-tg@comcast.com>
Brian Wakem wrote:
>> if ($name =~ /To:/) { &spamattempt; }
>
> Case insensitive regexs are very slow. I try to use index where
> possible, with a case modifier, which when I last did some benching on
> this issue was 6 times faster than a regex on my test machine IIRC.
>
> spamattempt() if (index(lc $name, 'to:') != -1);
A floating regex can be slow, but I expect the anchored regex
if ($name =~ /^To:/i) { spamattempt(); }
to be on par with index().
-Joe
------------------------------
Date: Tue, 18 Oct 2005 12:03:36 -0500
From: "AC" <clarke@n_o_s_p_a_m_hyperformix.com>
Subject: idiom for managing passed arguments?
Message-Id: <43552aa5$0$3764$39cecf19@news.twtelecom.net>
Greetings. I was wondering if there is an idiomatic way to handle passed
arguments to a subroutine. The "wanted" example below is shows what I'd
like, and the "works" example shows what I do right now...
sub wanted
{
my ($arg1, @args2to9, $arg10) = @_;
...
}
sub works
{
my ($arg1, @args2to9) = @_;
my $arg10 = splice(@args2to9, -1, 1);
...
}
Many Thanks,
Allan
------------------------------
Date: 18 Oct 2005 10:14:10 -0700
From: Lawrence Statton N1GAK/XE2 <lawrence@hummer.not-here.net>
Subject: Re: idiom for managing passed arguments?
Message-Id: <x7y84qrbml.fsf@hummer.i-did-not-set--mail-host-address--so-shoot-me>
"AC" <clarke@n_o_s_p_a_m_hyperformix.com> writes:
> Greetings. I was wondering if there is an idiomatic way to handle passed
> arguments to a subroutine. The "wanted" example below is shows what I'd
> like, and the "works" example shows what I do right now...
>
> sub wanted
> {
> my ($arg1, @args2to9, $arg10) = @_;
> ...
> }
>
> sub works
> {
> my ($arg1, @args2to9) = @_;
> my $arg10 = splice(@args2to9, -1, 1);
> ...
> }
>
> Many Thanks,
>
> Allan
>
>
#!/usr/bin/perl
use strict;
use warnings;
sub foo
{
my ($foo, @bar, $baz);
($foo, @bar[0..2], $baz) = @_;
print "Foo: $foo Bar: @bar Baz: $baz\n";
}
foo ( 1,2,3,4,5 );
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
sort them into the correct order.
------------------------------
Date: Tue, 18 Oct 2005 10:58:31 -0700
From: "David Schwartz" <davids@webmaster.com>
Subject: Re: Microsoft Hatred FAQ
Message-Id: <dj3d47$di6$1@nntp.webmaster.com>
"Roedy Green" <my_email_is_posted_on_my_website@munged.invalid> wrote in
message news:iv59l1d1h68mi5f2dns2lib5lvoi4vlr07@4ax.com...
> On Mon, 17 Oct 2005 22:21:55 -0700, "David Schwartz"
> <davids@webmaster.com> wrote or quoted :
>> I don't think any of it bordered on force or fraud. However, their
>>obligation to their shareholders requires them to do anythign that borders
>>on force/fraud so long as it isn't force/fraud.
> I avoid MS products whenever possible. Surely others feel the same
> way because we have had it up to the teeth with MS dirty tactics. That
> has to be factored into profitability as well.
Definitely. Sometimes you have to make nice if you want to make money.
I have no complaints with people who choose to avoid a particular
company's products because they don't like that company's tactics. And I
have no problem with them spreading their views and sharing their beliefs.
Heck, I work for a company that probably has made quite a few sales
because people were looking for a product by "anyone but Microsoft".
That said, I do agree there were some "dirty tactics" in the sense that
they were pure hardball and could have resulted in inferior products getting
greater market share. However, I don't think they came anywhere near force
or fraud, with very few exceptions.
Notable exceptions included cases where Microsoft told companies they
had no intention of releasing a competing product to get technical details
and later turned around and released competing products or cases where
Microsoft threatened legal action they knew they had no chance of winning at
a fair hearing. These did border on force/fraud and in some cases, Microsoft
did get spanked for these tactics.
DS
------------------------------
Date: Tue, 18 Oct 2005 17:58:31 GMT
From: cranium@blazenet.net (Rich Barnes)
Subject: Perl Script Question - Working with Directories
Message-Id: <11ladudjnev9b5@corp.supernews.com>
OK... This may seem like a dumb question, but I haven't figured out a way to
do this yet...
Given a directory, I want to be able to distinguish which entries are files
and which are directories... Actually I only want to list the directories in
my output.
In a shell script I can easily accomplish this:
*******************************
#!/bin/sh
cd /home/rbarnes
ls > /tmp/workfile
cat /tmp/workfile | \
while read VAR
do
if [ -d $VAR ]
then
echo $VAR
fi
done
rm /tmp/workfile
********************************************
How can I accomplish the same task in PERL... basically, if I had the TEST
command equiv in PERL I believe I could do this.
------------------------------
Date: Tue, 18 Oct 2005 16:57:28 +0100
From: "code_wrong" <tac@tac.ouch.co.uk>
Subject: where is my text file?
Message-Id: <43551b5c$1_3@mk-nntp-2.news.uk.tiscali.com>
hi,
I using the following script (from CGI and Perl in easy steps book) as a hit
counter:
it works ... but when I view the files on the host with WSFTP there is no
sign of counter.txt...
the script is in cgi-bin .. which is surely where counter.txt should appear
.. but there is no sign of it anywhere .. any ideas?
#!/usr/bin/perl
open(COUNT,"counter.txt");
$num = <COUNT>;
close(COUNT);
$num++;
open(COUNT, ">counter.txt");
print COUNT $num;
close(COUNT);
$num=sprintf("%05d", $num);
print "content-type:text/html\n\n <html>";
print "You are visitor number $num </html>";
------------------------------
Date: Tue, 18 Oct 2005 17:04:28 +0100
From: "code_wrong" <tac@tac.ouch.co.uk>
Subject: Re: where is my text file?
Message-Id: <43551cff$1_4@mk-nntp-2.news.uk.tiscali.com>
"code_wrong" <tac@tac.ouch.co.uk> wrote in message
news:43551b5c$1_3@mk-nntp-2.news.uk.tiscali.com...
> hi,
> I using the following script (from CGI and Perl in easy steps book) as a
> hit counter:
> it works ... but when I view the files on the host with WSFTP there is no
> sign of counter.txt...
> the script is in cgi-bin .. which is surely where counter.txt should
> appear .. but there is no sign of it anywhere .. any ideas?
DOH! .. found it ... I couldn't see it for looking at it ;-) it was in my
root directory on the host
------------------------------
Date: Tue, 18 Oct 2005 18:17:21 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: where is my text file?
Message-Id: <dj3eld.1dg.1@news.isolution.nl>
code_wrong:
> I using the following script (from CGI and Perl in easy steps book)
> as a hit counter:
Try <news:comp.infosystems.www.authoring.cgi>
Appending a 0-byte per visitor, to a sparse file if available, may be a
better approach.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Tue, 18 Oct 2005 11:41:45 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: where is my text file?
Message-Id: <eB95f.17$tT6.5367@news.uswest.net>
code_wrong wrote:
> "code_wrong" <tac@tac.ouch.co.uk> wrote in message
> news:43551b5c$1_3@mk-nntp-2.news.uk.tiscali.com...
>
>>hi,
>>I using the following script (from CGI and Perl in easy steps book) as a
>>hit counter:
>>it works ... but when I view the files on the host with WSFTP there is no
>>sign of counter.txt...
>>the script is in cgi-bin .. which is surely where counter.txt should
>>appear .. but there is no sign of it anywhere .. any ideas?
>
>
>
> DOH! .. found it ... I couldn't see it for looking at it ;-) it was in my
> root directory on the host
Wait a second.. The user-id running your Web server has write privilege
to your root directory? That's not good.
As for a counter, please see:
perldoc -q "I just want to increment the number in the file."
------------------------------
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 8537
***************************************