[22710] in Perl-Users-Digest
Perl-Users Digest, Issue: 4931 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 3 18:05:48 2003
Date: Sat, 3 May 2003 15:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 3 May 2003 Volume: 10 Number: 4931
Today's topics:
Re: =?ISO-8859-1?Q?string_checking,_before_using_in_SE? (Ole Borup)
Re: basic doubts.. <chang0@adelphia.net>
Checking administrator rights (Gert Vanderstukken)
Re: Checking administrator rights <clay@panix.com>
code optimization and readability <nas@ANTISPAMnasland.nu>
Re: code optimization and readability <dmcbride@naboo.to.org.no.spam.for.me>
Re: code optimization and readability <tassilo.parseval@rwth-aachen.de>
Compare Lists - built in Function? <aheissen@a1.net>
Re: Compare Lists - built in Function? <noreply@gunnar.cc>
Re: Compare Lists - built in Function? <fxn@hashref.com>
Re: Compare Lists - built in Function? <noreply@gunnar.cc>
Re: Compare Lists - built in Function? <tassilo.parseval@rwth-aachen.de>
Re: Compare Lists - built in Function? <noreply@gunnar.cc>
Re: Compare Lists - built in Function? <fxn@hashref.com>
Re: Compare Lists - built in Function? <noreply@gunnar.cc>
Re: Forms structure <flavell@mail.cern.ch>
how to change files in /var/spool/mail <xiamen2@hotmail.com>
Re: how to change files in /var/spool/mail <jurgenex@hotmail.com>
Re: how to change files in /var/spool/mail <abuse@mweb.co.za>
Re: Is there any way to debug PerlScript used in ASP? <45724remove@yahoo.com>
Re: Perl Editor : Whats Recommended <abuse@mweb.co.za>
Re: regex negating a search/word (Sara)
Re: string checking, before using in SENDMAIL -> =?iso- <bigj@kamelfreund.de>
Re: string checking, before using in SENDMAIL -> 'één' <go@away.spam>
Thread and shared data problem (Ole Borup)
uniquifying and accumulating (Julian Day)
Re: uniquifying and accumulating <jurgenex@hotmail.com>
Re: uniquifying and accumulating <krahnj@acm.org>
Re: waste of time (smugbuster)
Re: waste of time <galenmenzel@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 May 2003 12:51:11 -0700
From: oleborup@diku.dk (Ole Borup)
Subject: Re: =?ISO-8859-1?Q?string_checking,_before_using_in_SE?= =?ISO-8859-1?Q?NDMAIL_->_'=E9=E9n'_has_to_become_'een'?=
Message-Id: <a45993de.0305031151.363cc432@posting.google.com>
Hi
Try this function.
Note: This subroutine does not check that the email address actually
exists on the Internet, or that the domain name is valid, only that
that the format of the email address is correct. In my experience,
this catches the majority of problems.
- Ole
$a = "john\@somewhere.com";
print &CheckEmailAddress($a);
sub CheckEmailAddress() {
# This regexp validates the format of an email address. It returns the
cleaned
# version of the email address, or blank if the address was not valid.
#
# An email address must be of the form:
# 1) (trim any spaces or tabs or linefeeds or carriage returns)
# 2) (possibly one quotation mark)
# 3) (one or more characters for username, excepting a quotation mark)
# 4) (possibly one quotation mark)
# 5) @
# 6) (one or more characters for hostname(s), excepting [ <>\t])
# 7) .
# 8) (two or more characters for top-level-domain, excepting [ <>\t])
# 9) (trim any spaces or tabs or linefeeds or carriage returns)
#
# 1 2 3 4 56 7 8 9
# .............'''.......'''.'''''''''..''''''''''''''''''.............
$_[0] =~ /[ |\t|\r|\n]*\"?([^\"]+\"?@[^ <>\t]+\.[^ <>\t][^ <>\t]+)[
|\t|\r|\n]*/;
return $1;
}
"joe" <tunmaster@hotmail.com> wrote in message news:<9xLsa.1165127$sj7.47770038@Flipper>...
> Hi there,
>
> This is what it is. I'd like people to send emails through my site using
> SENDMAIL. But I'm afraid using the users input in the email, can hang the
> server if not checked properly. So I have to do some taintchecking. But I
> don't know what to expect for an email.
>
> I thought it to be a wise thing to replace all the not to often occurring
> characters with a questionmark, like this:
> $::x2 =~ s/[^\w\s\n.,:;+-=\[\]()!@#$%&?<>]/?/g;
> I can perfectly live with that, wasn't it that a string like "Één
> goedemiddag" will become "??n goedemiddag".
>
> Is there a better way to make sure a string doesn't contain any dangerous
> codes or if I like the above code, it's just fine. But how than can I make
> "Een goedemiddag" out of the first string?
------------------------------
Date: Sat, 03 May 2003 15:26:31 GMT
From: ebchang <chang0@adelphia.net>
Subject: Re: basic doubts..
Message-Id: <Xns93707464DD3D5chang0adelphia.net@24.48.107.54>
"Nico Coetzee" <abuse@mweb.co.za> wrote in
news:pan.2003.05.03.13.52.36.171649@mweb.co.za:
> On Sat, 03 May 2003 13:19:24 +0000, ebchang wrote:
>
>> viijv@rediffmail.com (Rajesh M A) wrote in
>> news:bf3db5a0.0305030418.668437f3@posting.google.com:
>>
>>> Hello Group,
>>
[snip}
>> (Apologies for sounding like an advertisement, but the OP did quote
>> the exercises, and the information is all in the textbook, even if he
>> couldn't possibly have it yet.)
>
> Well then - there you have it...
>
No, I don't have it yet. But the original typesetter, located in India,
does. :)
Incidentally, I didn't mind having the exercises used, but I wish the first
one hadn't been garbled in the process.
--
EBC
------------------------------
Date: 3 May 2003 13:14:39 -0700
From: gert.vanderstukken@pandora.be (Gert Vanderstukken)
Subject: Checking administrator rights
Message-Id: <5eb4ae79.0305031214.54ed6e9f@posting.google.com>
Hello all,
I'm looking for a way to check if the script is ran under an
administrative account, but I cannot seem to find it.
I'm new to Perl, so I can use some help...
Kind regards,
Gert Vanderstukken
gert.vanderstukken@pandora.be
Leuven
Belgium
------------------------------
Date: Sat, 3 May 2003 21:22:49 +0000 (UTC)
From: Clay Irving <clay@panix.com>
Subject: Re: Checking administrator rights
Message-Id: <slrnbb8cp9.qhv.clay@panix3.panix.com>
In article <5eb4ae79.0305031214.54ed6e9f@posting.google.com>,
Gert Vanderstukken wrote:
> I'm looking for a way to check if the script is ran under an
> administrative account, but I cannot seem to find it.
perldoc perlvar
--
Clay Irving <clay@panix.com>
Anyway, my money is still on use strict vars . . .
-- Larry Wall in <199710011704.KAA21395@wall.org>
------------------------------
Date: Sat, 03 May 2003 18:43:52 GMT
From: "Chris H." <nas@ANTISPAMnasland.nu>
Subject: code optimization and readability
Message-Id: <I5Usa.14280$g41.1033550@news1.east.cox.net>
i wrote/started a website a couple years ago. written initially in php/mysql
then later "ported" it to perl/postgresql 2 years later. from the first
time it went perl up until present it ran basically off the same (junk)
codebase. it wasn't very dynamic, hence making a template change to change
the design/layout of the site meant re-doing a lot of the code base because
the html was embedded (a nasty thing i picked up from php (not a php flame
mind you)). one of my requirements this go around was to make the site
extremely flexible, and make it easy to create "themes" for, and of course
have user submitted/user selected themes.
i have run in to several snags along the way, however. before i get to that,
here's some background on what i have done with perl. the past 3 years i
have worked for an isp as a perl (mainly) programmer. so, a lot of the
stuff i worked on was either already created and needed some fixes (jimmy
rigged) done so they'd work again, or doing the usual form mailers. i only
got to do original stuff a couple times, and the biggest (unfortunately)
was a perl/nt/mssql application which turned out pretty decent and worked
quite well (fortunately). this has been my main experience with perl,
except for what i would learn on the side doing my own projects and
building the site mentioned currently to learn more/faster/better ways of
doing things.
hence, the problems i have run into is trying to "think differently" (sorry
apple :). trying to get out of the "simple" mindset and into the
"creation/innovation" mindset. with this, i have essentially created a
monster. the site now executes more database queries (nearly twice), and
the "template system" i've built means statically setting up "parsers" for
the template.
at the present, the site is about 95% complete, with only a couple trivial
scripts left to complete before i can launch the new codebase. however, i
decided that the direction i was going wasn't exactly optimized for several
thousand hits/day (if i ever got that much). so i started a line by line
"audit" of the code. using some tips from the good ol' camel book i
proceeded to go through the scripts line by line seeing if i could write
this line better or more efficient, or that block could be minimized to
execute faster.
also reading the tips, i hear calling functions cost more cpu cycles than if
the code was outside of a function. which is a lot different than the way
i've been taught of modularizing code by creating functions to make it
easier to update code should you need to. so, thus began the guessing game
of what to leave "in-line" and what functions had to absolutely be in
functions. tricky game...
this all brings me up to date with where i am now. the file i'm working on
now is really the problem area. its a bloated s.o.b. that needs some major
changes. being that its the heart of the site for the most part, being
called from every page to read the templates, and spit back html...it
really needs to be as fast and as streamlined as possible.
so with all that said (sorry), i come here. looking for some help/tips/etc
on how to improve this behemoth. basically what i am looking for are better
ways to do things, but also looking for tips on how to improve the
readability of the code. in the past its always been functionality over
readability, this time i want both. i'm looking for that elusive "uber"
codebase that when opened by someone who doesn't even know perl to say, "ya
know, i don't understand what this is doing but its sexy as hell. when i
learn perl, i'd like for my code to turn out like this." rather improbable,
but not impossible. i know there are always tradeoffs when dealing with
this topic, which even more questions stem such as, "should i use this, or
should i use that? hrm..."
before i post the links to the file, i'd like to first apologize for the
length of this, it was not my intention to make it as long winded as it
turned out. secondly, the html page generated will not show proper code
spacing due to not being a fixed width font (unless you have that over
ridden in your browser of course). so i have two links, the first is the
html page with syntax highlighted (thank gvim for including this handy
feature), and the second is a plain text file for those who don't need/want
the syntax highlighting and would prefer the text file due to it being more
commonly displayed with a fixed with font.
http://www.nasland.nu/template.pl.html
http://www.nasland.nu/template.pl.txt
(sorry for the hell you're about to endure if you choose to look at the
code)
i appreciate your time
-chris h
------------------------------
Date: Sat, 03 May 2003 20:02:37 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: code optimization and readability
Message-Id: <xfVsa.258218$vs.21302624@news3.calgary.shaw.ca>
Chris H. wrote:
> before i post the links to the file, i'd like to first apologize for the
> length of this, it was not my intention to make it as long winded as it
> turned out. secondly, the html page generated will not show proper code
> spacing due to not being a fixed width font (unless you have that over
> ridden in your browser of course). so i have two links, the first is the
> html page with syntax highlighted (thank gvim for including this handy
> feature), and the second is a plain text file for those who don't
> need/want the syntax highlighting and would prefer the text file due to it
> being more commonly displayed with a fixed with font.
>
> http://www.nasland.nu/template.pl.html
> http://www.nasland.nu/template.pl.txt
>
> (sorry for the hell you're about to endure if you choose to look at the
> code)
First recommendation: toss the idea of reinventing wheels. There are a
number of good templating systems in Perl already - Text::Template,
HTML::Template, etc. Many of these already have decent to superb
optimisations in them. For example, H::T can use shared memory to store
pre-parsed templates, or a file cache of them. T::T probably does
something similar.
The next thing is the way you interact with the http server. Try using
something that simplifies this. For example, CGI::Application. It makes
much of this job easier.
Rather than "BEGIN { push @INC ... }", try use lib "<taken out>"; instead.
A lot more clear.
Rather than reading a config file ... use one of the modules that reads
config files.
This should help remove most of your code, which means that your code will
be more flexible.
------------------------------
Date: 3 May 2003 20:29:07 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: code optimization and readability
Message-Id: <b918qj$ntj$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Chris H.:
[...]
> so with all that said (sorry), i come here. looking for some help/tips/etc
> on how to improve this behemoth. basically what i am looking for are better
> ways to do things, but also looking for tips on how to improve the
> readability of the code. in the past its always been functionality over
> readability, this time i want both. i'm looking for that elusive "uber"
> codebase that when opened by someone who doesn't even know perl to say, "ya
> know, i don't understand what this is doing but its sexy as hell. when i
> learn perl, i'd like for my code to turn out like this." rather improbable,
> but not impossible. i know there are always tradeoffs when dealing with
> this topic, which even more questions stem such as, "should i use this, or
> should i use that? hrm..."
I didn't have a more in-depth look into your code but some things are a
little clumsy and costly in terms of CPU-cycles than they could be.
First of all, something like this:
sub print_news_tmpl {
my @return_text;
my $news_date = $_[0];
my $news_time = $_[1];
my $news_author = $_[2];
my $news_content = $_[3];
my $news_title = $_[4];
my $news_aemail = $_[5];
...
}
This is lot to type and slower than simply writing:
sub print_news_tmpl {
my ($news_date, $news_time, $news_author,
$news_content, $news_title, $news_aemail) = @_;
my @return_text;
...
}
According to Benchmark.pm this saves about 20%.
Then you are doing some redundant checks (I think):
if(%cookie) {
if($cookie{dpcookie}) {
$dpcookie = $cookie{dpcookie}->value;
$dpcookie = pack("H*", $dpcookie);
($cuname, $cupass, $cutype) = split(/;/, $dpcookie);
&verify_cookie_data($cuname, $cupass);
$logged_in = 1;
}
}
# set theme to default unless logged in
my $theme_name = "default";
if ($logged_in == 1) {
my @get_user_theme = ...;
...
}
If I read the above correctly you can save at least two if-conditions:
my $theme_name = "default";
if ($cookie{dpcookie}) {
$dpcookie = $cookie{dpcookie}->value;
$dpcookie = pack("H*", $dpcookie);
($cuname, $cupass, $cutype) = split(/;/, $dpcookie);
verify_cookie_data($cuname, $cupass);
$logged_in = 1;
($theme_name) = db_query (...);
}
The iterations over some files could be sped up, too. First rule is to
skip lines as early as possible, so:
while (<CFG>) {
next if /^[\s#]*$/;
chomp;
...
}
's/\n//g' is not a good way of removing newlines at the end of a string.
Use chomp() for that or - if you want to remove them unconditionally
from a string - 'tr/\n//d'.
The while-loop in parse_theme_config() could be done with a
dispatch-table:
...
my %dispatch = (
LinksDelimeter => sub {
($links_delimiter = $_[0]) =~ tr/s/ /;
},
SiteLinksDisplay => sub { ... },
...
);
while (<CFG>) {
chomp;
my ($key, $value) = /(.*?)=(.*)/;
next if ! exists $dispatch{ $key };
$dispatch{ $key }->($value);
}
Had you used a hash for the several configuration keys it'd be even
easier and quicker:
my %theme_config;
sub parse_theme_config {
...
while (<CFG>) {
my ($key, $value) = /(.*?)=(.*?)/ or next;
$theme_config{ $key } = $value;
}
}
I see a lot of such code that could be written more idiomatically and
thus would be more readable and quicker. Remember that Perl offers many
ways to do something. Employing conditional code for example can often
be reduced to one line or so (as shown in the snippet above).
Another thing that I would consider is using one of the many templating
modules available from the CPAN instead of rolling your own.
Also, keep an eye on database issues. Often a database is queried more
often than it would be necessary. Furthermore code like
db_query ("select user_theme from users where uname = '$cuname'");
suggests that you may not be doing it properly. You are almost certainly
using DBI so remember that you can do
my $sth = $dbh->prepare("select user_theme from users where uname = ?");
# now one of the fetch* methods
my $data = $sth->fetchall_hashref($cuname);
Those were just a few random remarks. Others might observe different
things to improve.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 03 May 2003 18:14:20 GMT
From: "news.chello.at" <aheissen@a1.net>
Subject: Compare Lists - built in Function?
Message-Id: <0GTsa.11606$e8.141057@news.chello.at>
Is there any builtin function which does a compare of two sorted lists? I
only need true for 2 lists with the same values.
thanx
------------------------------
Date: Sat, 03 May 2003 21:07:21 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Compare Lists - built in Function?
Message-Id: <b91458$ep6v0$1@ID-184292.news.dfncis.de>
news.chello.at wrote:
> Is there any builtin function which does a compare of two sorted
> lists? I only need true for 2 lists with the same values.
Maybe you could compare two interpolated arrays:
if ("@list1" eq "@list2") {
print 'Identical lists';
} else {
print 'Not identical lists';
}
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 3 May 2003 19:23:02 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: Re: Compare Lists - built in Function?
Message-Id: <b914um$na4$1@news.ya.com>
In article <b91458$ep6v0$1@ID-184292.news.dfncis.de>, Gunnar Hjalmarsson wrote:
: news.chello.at wrote:
:> Is there any builtin function which does a compare of two sorted
:> lists? I only need true for 2 lists with the same values.
:
: Maybe you could compare two interpolated arrays:
:
: if ("@list1" eq "@list2") {
: print 'Identical lists';
: } else {
: print 'Not identical lists';
: }
Nope:
@list1 = (qq(foo$"bar));
@list2 = ('foo', 'bar');
This is in the FAQ:
perldoc -q 'How do I test whether two arrays or hashes are equal?'
-- fxn
------------------------------
Date: Sat, 03 May 2003 22:13:41 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Compare Lists - built in Function?
Message-Id: <b9181l$eojdc$1@ID-184292.news.dfncis.de>
Xavier Noria wrote:
> In article <b91458$ep6v0$1@ID-184292.news.dfncis.de>, Gunnar Hjalmarsson wrote:
>
> : news.chello.at wrote:
> :> Is there any builtin function which does a compare of two sorted
> :> lists? I only need true for 2 lists with the same values.
> :
> : Maybe you could compare two interpolated arrays:
> :
> : if ("@list1" eq "@list2") {
> : print 'Identical lists';
> : } else {
> : print 'Not identical lists';
> : }
>
> Nope:
>
> @list1 = (qq(foo$"bar));
> @list2 = ('foo', 'bar');
Okay, Xavier, I admit that you called our attention to a _limitation_
with the above approach. ;-) At the same time I suppose that there
are situations where you can be pretty sure that there are no
occurrences of interpolated elements that include the $" variable...
> This is in the FAQ:
>
> perldoc -q 'How do I test whether two arrays or hashes are equal?'
If I modify my suggestion to:
if ("@list1" eq "@list2" and @list1 == @list2) {
print 'Identical lists';
} else {
print 'Not identical lists';
}
I'd say that it does effectively the same thing as the first FAQ
example. Comments?
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 3 May 2003 20:39:08 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Compare Lists - built in Function?
Message-Id: <b919dc$o9h$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Gunnar Hjalmarsson:
> Xavier Noria wrote:
>> This is in the FAQ:
>>
>> perldoc -q 'How do I test whether two arrays or hashes are equal?'
>
> If I modify my suggestion to:
>
> if ("@list1" eq "@list2" and @list1 == @list2) {
> print 'Identical lists';
> } else {
> print 'Not identical lists';
> }
>
> I'd say that it does effectively the same thing as the first FAQ
> example. Comments?
If you insist on doing it that way, at least set $" to an unlikely
value. Possibly something binary such as \030 or even a multi-character
string.
Still it's a very fragile construct that can always fail under
unfortunate circumstances.
Anyway, there was a time when I thought I could handle list comparisons
with string interpolation, too. In the end it always gave me a bloody
nose because someone here found a counter-example. I think you have just
entered this stage. ;-)
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 03 May 2003 22:48:10 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Compare Lists - built in Function?
Message-Id: <b91a2c$efhtu$1@ID-184292.news.dfncis.de>
Tassilo v. Parseval wrote:
> Also sprach Gunnar Hjalmarsson:
>> Xavier Noria wrote:
>>> This is in the FAQ: perldoc -q 'How do I test whether two
>>> arrays or hashes are equal?'
>>
>> If I modify my suggestion to:
>>
>> if ("@list1" eq "@list2" and @list1 == @list2) {
>> print 'Identical lists';
>> } else {
>> print 'Not identical lists';
>> }
>>
>> I'd say that it does effectively the same thing as the first FAQ
>> example. Comments?
>
> If you insist on doing it that way, at least set $" to an unlikely
> value. Possibly something binary such as \030 or even a
> multi-character string.
>
> Still it's a very fragile construct that can always fail under
> unfortunate circumstances.
>
> Anyway, there was a time when I thought I could handle list
> comparisons with string interpolation, too. In the end it always
> gave me a bloody nose because someone here found a counter-example.
> I think you have just entered this stage. ;-)
Yeah, so it seems. But note that the modified example is a combination
of string interpolation and element counting. To speed up my entering
into the next stage, I'm waiting for an example that proves that the
first sub in the FAQ is safer. :)
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 3 May 2003 21:25:28 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: Re: Compare Lists - built in Function?
Message-Id: <b91c48$5br$1@news.ya.com>
In article <b91a2c$efhtu$1@ID-184292.news.dfncis.de>, Gunnar Hjalmarsson wrote:
: Yeah, so it seems. But note that the modified example is a combination
: of string interpolation and element counting. To speed up my entering
: into the next stage, I'm waiting for an example that proves that the
: first sub in the FAQ is safer. :)
These pass the test:
@list1 = ('foo', 'bar baz');
@list2 = ('foo bar', 'baz');
The trick joining with a binary char remains me of the pack/unpack idea
Benjamin Goldberg contributed to Hash::MultiKey. It's documented in the
implementation overview at the top of the file:
http://search.cpan.org/author/FXN/Hash-MultiKey-0.05/MultiKey.pm
-- fxn
------------------------------
Date: Sat, 03 May 2003 23:37:48 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Compare Lists - built in Function?
Message-Id: <b91cvg$e9qer$1@ID-184292.news.dfncis.de>
Xavier Noria wrote:
> In article <b91a2c$efhtu$1@ID-184292.news.dfncis.de>, Gunnar
> Hjalmarsson wrote:
>>
>>Yeah, so it seems. But note that the modified example is a
>>combination of string interpolation and element counting. To
>>speed up my entering into the next stage, I'm waiting for an
>>example that proves that the first sub in the FAQ is safer. :)
>
> These pass the test:
>
> @list1 = ('foo', 'bar baz');
> @list2 = ('foo bar', 'baz');
Hmm.. Yes, of course they do.
Okay, I give up. Thought I had found a short-cut compared to matching
each element, but I should have known better than believing I was
smarter than the FAQ. ;-)
Thanks, Xavier and Tassilo, for the lesson.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 3 May 2003 17:15:05 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Forms structure
Message-Id: <Pine.LNX.4.53.0305031711050.31909@lxplus087.cern.ch>
On Sat, May 3, Andrew Lee inscribed on the eternal scroll:
> On Fri, 2 May 2003 23:55:17 +0200, "Alan J. Flavell"
> <flavell@mail.cern.ch> wrote:
>
> >CGI programs are written in a wide range of languages (I've seen
> >perfectly serious discussions of CGI programs written in COBOL, for
> >example).
>
> I never said cgi's weren't written in other languages ...
I'm sorry, I hadn't intended to imply that _you_ didn't know that: my
remark was really aimed at the gallery, considering that this group
often gets irritated by newbies who think that Perl exists only for
writing CGI scripts and that CGI scripts can only be written in Perl:
I had no doubt that you were aware than neither of these is true, but
somehow, in composing my response "on the hoof" I didn't make my
meaning very clear.
Cheers
--
The difficulty arises because the kind of people who can sell to
your powers-that-be are incompatible with those of us with a clue
on technical subjects. - Nick Kew on c.i.w.a.stylesheets
------------------------------
Date: Sun, 4 May 2003 00:47:36 +0800
From: "news.pacific.net.sg" <xiamen2@hotmail.com>
Subject: how to change files in /var/spool/mail
Message-Id: <b90rpj$mhf$1@nobel.pacific.net.sg>
Hi,
I'm trying to use a cgi to change files in /var/spool/mail with suidperl.
could anyone give me a sample script for doing this?
I'm using perl5.8.0.
Thx, GF
------------------------------
Date: Sat, 03 May 2003 17:37:37 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: how to change files in /var/spool/mail
Message-Id: <B7Tsa.6391$gf3.3481@nwrddc03.gnilink.net>
news.pacific.net.sg wrote:
> I'm trying to use a cgi to change files in /var/spool/mail with
> suidperl. could anyone give me a sample script for doing this?
What are you talking about? Interfaces don't change files. CGI defines,
well, a communication interface between two processes. It does not have an
operation of "change a file"
jue
------------------------------
Date: Sat, 03 May 2003 23:39:19 +0200
From: "Nico Coetzee" <abuse@mweb.co.za>
Subject: Re: how to change files in /var/spool/mail
Message-Id: <pan.2003.05.03.21.39.18.271631@mweb.co.za>
On Sun, 04 May 2003 00:47:36 +0800, news.pacific.net.sg wrote:
> Hi,
>
> I'm trying to use a cgi to change files in /var/spool/mail with suidperl.
> could anyone give me a sample script for doing this?
>
> I'm using perl5.8.0.
>
> Thx, GF
/var/spool/mail is part of the Unix mail system, so use a standard
interface, or use IMAP/POP3.
--
Nico Coetzee
http://www.itfirms.co.za/
http://za.pm.org/
http://forums.databasejournal.com/
To the systems programmer, users and applications serve only to provide a
test load.
------------------------------
Date: Sat, 3 May 2003 17:06:29 -0400
From: "Andrew" <45724remove@yahoo.com>
Subject: Re: Is there any way to debug PerlScript used in ASP?
Message-Id: <b91avs$ela2r$1@ID-51798.news.dfncis.de>
Thanks Rudolf, but I still hope there's a debugger...
Does any one know if InterDev or Microsoft Script Debuger would
work with PerlScript ?
Or maybe there is any other debugger that can debug PerlScript in
ASP ?
In general ASP+PerlScript is a good combination for IIS,much better than PHP (performance & security ), it's a pitty everyone has
ignored it.
Perl is here for many years, and still is the best language ever for web
tasks.
------------------------------
Date: Sat, 03 May 2003 17:18:26 +0200
From: "Nico Coetzee" <abuse@mweb.co.za>
Subject: Re: Perl Editor : Whats Recommended
Message-Id: <pan.2003.05.03.15.18.25.455893@mweb.co.za>
On Sat, 03 May 2003 10:43:34 +0000, Rudolf Polzer wrote:
--snip--
>
> vi doesn't have that feature, but something else which might be good in those
> cases:
>
> You see:
>
> # ...
> }
> else
> {
> # ...
> }
>
> Move over the closing brace before the else and press %. You will be
> near the matching if.
Cool tip - thanks
--
Nico Coetzee
http://www.itfirms.co.za/
http://za.pm.org/
http://forums.databasejournal.com/
To the systems programmer, users and applications serve only to provide a
test load.
------------------------------
Date: 3 May 2003 13:03:47 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: regex negating a search/word
Message-Id: <776e0325.0305031203.5fbc0da0@posting.google.com>
Eric Schwartz <emschwar@pobox.com> wrote in message news:<etoel3h3x3x.fsf@wormtongue.emschwar>...
> genericax@hotmail.com (Sara) writes:
> > # now truncate the inputfile at /TABLE\s+71/
> > $f =~ s/TABLE\s+71.+$//sm;
> > $f =~ s/^.*TABLE\s+70.*?TELEVISION.*?(\d{1,3}\.\d).+$/$1/;
> >
> > # at this point $f either contains $1, if it matched, or the truncated
> > file if
> > # it didn't. There are a few ways to test that, perhaps another regex?
>
> Ack, no. Just test the result of the one you just applied:
>
> if($f =~ s/$regex/) {
> <do stuff with $1>
> } else {
> <complain about not matching, or whatever>
> }
Eric:
Quite right.. Perhaps the simplest:
if (defined $1)
{do stuff}
else
{whine();}
------------------------------
Date: Sat, 03 May 2003 21:27:00 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: string checking, before using in SENDMAIL -> =?iso-8859-1?b?J+npbic=?= has to become 'een'
Message-Id: <pan.2003.05.03.19.25.46.848441@kamelfreund.de>
joe wrote at Sat, 03 May 2003 08:58:45 +0000:
> I thought it to be a wise thing to replace all the not to often
> occurring characters with a questionmark, like this: $::x2 =~
> s/[^\w\s\n.,:;+-=\[\]()!@#$%&?<>]/?/g; I can perfectly live with that,
> wasn't it that a string like "Één goedemiddag" will become "??n
> goedemiddag".
>
> Is there a better way to make sure a string doesn't contain any
> dangerous codes or if I like the above code, it's just fine. But how
> than can I make "Een goedemiddag" out of the first string?
>
> I'd really appreciate it if someone could help me out here!
I wrote a module Lingua::DE::ASCII (availabe on CPAN) doing similar stuff.
Allthough it's intended for german, it also has a method
to_ascii($string)
converting an iso latin1 string to reasonable ascii string (only
consisting of 7bit ASCII codes).
For that, letters like é è are translated to e, and other like ä,ö,ü
are translated to ae,oe,ue and so on.
Perhaps it can help you.
Basically, the operation done by this method is also quite simple.
I just define a hash of the necessary translation,
let's say
my %ascii = (qw(
À A
Á A
 A
à A
Ä Ae
Å A
Æ Ae
)); # and so on
and then a substitution
$text =~ s/([$non_ascii_char])/$ascii{$1}/eg;
where is
$non_ascii_char = join "", map {chr} (128..255);
Greetings,
Janek
------------------------------
Date: Sat, 3 May 2003 18:12:20 +0200
From: "LaDainian Tomlinson" <go@away.spam>
Subject: Re: string checking, before using in SENDMAIL -> 'één' has to become 'een'
Message-Id: <b90pp6$fsf$1@news.lth.se>
"joe" <tunmaster@hotmail.com> wrote:
<snip>
> Is there a better way to make sure a string doesn't contain any dangerous
> codes or if I like the above code, it's just fine. But how than can I make
> "Een goedemiddag" out of the first string [Één goedemiddag]?
Try the tr/// function.
my $x = "Één goedemiddag";
$x =~ tr/Éé/Ee/;
print $x;
Brandan L.
--
bclennox AT eos DOT ncsu DOT edu
------------------------------
Date: 3 May 2003 12:38:25 -0700
From: oleborup@diku.dk (Ole Borup)
Subject: Thread and shared data problem
Message-Id: <a45993de.0305031138.79585761@posting.google.com>
Hi
I am making a perl program using threads, but got some odd problems
using shared variables.
To illustrate I used an example from "Programming Perl 3rd Edition
(O'Reilly)" page 456.
#!/usr/bin/perl
use Thread qw(async yield);
my $var = 0;
print \$var."\n";
sub abump {
if ($var == 0) {
yield;
$var++;
}
print \$var."\n";
}
my $t1 = new Thread(\&abump);
my $t2 = new Thread(\&abump);
for my $t ($t1, $t2) { $t->join }
print "var is $var\n";
print \$var."\n";
As the output shows, it isn't the same $var used in the two threads
and the main program:
SCALAR(0x8060d04)
SCALAR(0x812acd4)
SCALAR(0x8189d14)
var is 0
SCALAR(0x8060d04)
I am using "This is perl, v5.8.0 built for i386-linux-thread-multi"
and have tried on both RedHat 8.0 and Mandrake 9.0 with the same
result.
What am I missing here, everything I found about shared variables
indicated that $var should shared.
- Ole Borup
------------------------------
Date: 3 May 2003 10:24:58 -0700
From: syzygyooo@yahoo.ca (Julian Day)
Subject: uniquifying and accumulating
Message-Id: <c0cbb4b4.0305030924.5a305b66@posting.google.com>
Hi,
Looking for an idiomatic (that is concise and perlish) way to flatten
a list of names while accumulating associated values:
Before:
john:10
john:2
robert:15
robert:20
sally:4
After:
john:12
robert:35
sally:4
I'm surely missing something obvious (and can, accordingly, feel the
flames licking at my heels ;-) but somehow I can't seem to get it
right.
/Julian
------------------------------
Date: Sat, 03 May 2003 17:40:43 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: uniquifying and accumulating
Message-Id: <vaTsa.6417$gf3.866@nwrddc03.gnilink.net>
Julian Day wrote:
> Looking for an idiomatic (that is concise and perlish) way to flatten
> a list of names while accumulating associated values:
>
> Before:
>
> john:10
> john:2
> robert:15
> robert:20
> sally:4
>
> After:
>
> john:12
> robert:35
> sally:4
>
>
> I'm surely missing something obvious (and can, accordingly, feel the
> flames licking at my heels ;-) but somehow I can't seem to get it
> right.
Trivial with a hash. Use the names as keys, the numbers as values, and just
add them up:.
#untested
for (@namelist) {
my ($name, $number) = split /:/;
$accumulated{$name} += $number;
}
jue
------------------------------
Date: Sat, 03 May 2003 20:25:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: uniquifying and accumulating
Message-Id: <3EB425C5.3CB4AA15@acm.org>
Julian Day wrote:
>
> Looking for an idiomatic (that is concise and perlish) way to flatten
> a list of names while accumulating associated values:
>
> Before:
>
> john:10
> john:2
> robert:15
> robert:20
> sally:4
>
> After:
>
> john:12
> robert:35
> sally:4
>
> I'm surely missing something obvious (and can, accordingly, feel the
> flames licking at my heels ;-) but somehow I can't seem to get it
> right.
perl -F: -lane'$h{$F[0]}+=$F[1]}{print"$_:$h{$_}"for sort keys%h'
yourfile
John
--
use Perl;
program
fulfillment
------------------------------
Date: 3 May 2003 10:51:02 -0700
From: smugbuster@hotmail.com (smugbuster)
Subject: Re: waste of time
Message-Id: <677cff64.0305030951.79f9a324@posting.google.com>
genericax@hotmail.com (Sara) wrote in message news:<776e0325.0305020524.6b4e752a@posting.google.com>...
> smugbuster@hotmail.com (smugbuster) wrote in message news:<677cff64.0304300948.7e8878c4@posting.google.com>...
> > your little newsgroup or whatever you call it is a waste of time for
> > anybody trying to learn anything new.
> >
> Yes exactly we call it "our little newsgroup". Just the other day I
> was saying to Uri= "Hey Uri, our little newsgroup..."
>
> > legitimate questions are disparaged, ridiculed, and made fun of.
> > what's wrong with you people? you were all newbies once!
> We have something wrong with us indeed. This is likely the most
> helpful, responsive group of contributors of all the groups. Tell ya
> what- run this experiment. Dream up an generic newbie question and
> post it to the linux, python, perl, and java groups and look at the
> results. Chances are you'll get NOTHING from most groups, flamed by
> the linux types, and "remanded" here to go to the docs.
>
> >
> > my guess is that half of you don't know what you're talking about
> > anyway.
> >
> Well the other third of us sure do buddy!
>
> > don't you have anything better to do than to get online and "flame"
> > people that may not have as much knowledge of the subject as you.
> > pathetic.
> >
> Yes that's our little lot in life. We've dedicated ourselves to the
> "Perlista Church of the Eternal Flame".
>
> > i suggest you get a life. you're all a little too smug for your own
> > good.
> OK, I'll see what I can find.
>
>
> >
> > oh, also, i guess i'm not cool because i don't have a witty quip at
> > the end of my message, or use case sensitive words or end plural words
> > with a string of "z's."
> >
>
> Agreed.. I won't use "Washington DC" or
> 'Birds of a Feather' . 'zzz';
>
> > jack
>
> -Sara
Thank you all for participating in my little "sociological
experiment." I'm doing my masters thesis on internet communication. I
have never even visited your newsgroup before I posted my original
message.
Sorry to have deceived you! I'm sure that you are all very dedicated
perl programmers and share your knowledge openly.
A few of the retorts were great! Thanks to Sara for the line 'I won't
use Washington DC'! That was great!
Again, I apologize and will not post any messages in the future.
JDA
------------------------------
Date: 3 May 2003 20:44:45 GMT
From: Galen Menzel <galenmenzel@yahoo.com>
Subject: Re: waste of time
Message-Id: <slrnbb8ap9.10c.galenmenzel@localhost.localdomain>
In article <677cff64.0305030951.79f9a324@posting.google.com>, smugbuster wrote:
> genericax@hotmail.com (Sara) wrote in message news:<776e0325.0305020524.6b4e752a@posting.google.com>...
>> smugbuster@hotmail.com (smugbuster) wrote in message news:<677cff64.0304300948.7e8878c4@posting.google.com>...
>
> <snip>
>
> Thank you all for participating in my little "sociological
> experiment." I'm doing my masters thesis on internet communication. I
> have never even visited your newsgroup before I posted my original
> message.
>
> Sorry to have deceived you! I'm sure that you are all very dedicated
> perl programmers and share your knowledge openly.
>
> A few of the retorts were great! Thanks to Sara for the line 'I won't
> use Washington DC'! That was great!
>
> Again, I apologize and will not post any messages in the future.
Wow. Who says academics don't do anything useful?
galen
------------------------------
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.
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 4931
***************************************