[22562] in Perl-Users-Digest
Perl-Users Digest, Issue: 4783 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 29 14:06:02 2003
Date: Sat, 29 Mar 2003 11: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 Sat, 29 Mar 2003 Volume: 10 Number: 4783
Today's topics:
==>>Интернет работа / телеработа от 300$... wedweb@nm.ru
Re: CGI.pm or roll-your-own? (Randal L. Schwartz)
Re: CGI.pm or roll-your-own? <bkennedy@hmsonline.com>
Re: CGI.pm or roll-your-own? <noreply@gunnar.cc>
Re: CGI.pm or roll-your-own? <noreply@gunnar.cc>
Re: CGI.pm or roll-your-own? <uri@stemsystems.com>
Re: CGI.pm or roll-your-own? <noreply@gunnar.cc>
Re: CGI.pm or roll-your-own? <bkennedy@hmsonline.com>
Re: CGI.pm or roll-your-own? (Randal L. Schwartz)
Re: CGI.pm or roll-your-own? <noreply@gunnar.cc>
Re: DBI problem <goldbb2@earthlink.net>
Re: implicit vs explicit variable usage in loop w/ rang (Upstart)
Re: implicit vs explicit variable usage in loop w/ rang (Upstart)
Re: match all but this <abigail@abigail.nl>
Re: match except between... <abigail@abigail.nl>
Re: Multiple POSTS and GETS from one perl script <idont@thinkso.net>
Re: Multiple POSTS and GETS from one perl script <meanblue@rascalsdesign.biz>
Re: Multiple POSTS and GETS from one perl script <noreply@gunnar.cc>
Re: Multiple POSTS and GETS from one perl script <idont@thinkso.net>
Re: Multiple POSTS and GETS from one perl script <meanblue@rascalsdesign.biz>
Re: Perl and Objects (kinda OT) <idont@thinkso.net>
Perl and objects <mail@annuna.com>
Re: Perl and Objects <mail@annuna.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 29 Mar 2003 15:11:13 +0000 (UTC)
From: wedweb@nm.ru
Subject: ==>>Интернет работа / телеработа от 300$...
Message-Id: <b64d2g$2gbv$1@relay.cca.usart.ru>
Наверняка Вы уже слышали, что тысячи людей во всем мире пользуются Интернетом по нескольку
часов в неделю для поиска различной информации, чтения новостей и переписки с друзьями,
и зарабатывают при этом деньги.
Что бы Вы сказали, если бы уже сегодня Вам предложили такую возможность?
Именно для того, что бы описать теорию и практику одного из видов бизнеса в Интернет,
мы и создали данный сайт на www.wedweb.nm.ru <http://www.wedweb.nm.ru>.
Предлагаем ознакомиться с идеей бизнеса ...Если есть вопросы пишите на wedweb@nm.ru <mailto:wedweb@nm.ru>
P.S
Новый рекламный ролик:
Буш стоит на фоне стартующих томагавков и взлетающих Б-52, Ф-14 и Ф-18....
На заднем фоне реет американский флаг...
Буш произносит фразу: "Вы все еще не верите в демократию? Тогда мы летим к Вам!!!"
------------------------------
Date: Sat, 29 Mar 2003 15:41:52 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <d8bc7e844348167aad599b62ddf0002b@news.teranews.com>
>>>>> "Gunnar" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
Tintin> 1. Only supports POST requests.
Tintin> 2. Open to buffer overflows.
Tintin> 3. Doesn't handle ; as a parameter separator
>> 4. doesn't handle multivalue options. Common problem.
Gunnar> Hmm.. Taking into consideration that the module does not include any
Gunnar> multivalue options, how can that be a problem? ;-) As I pointed out
Gunnar> to Tintin, the readform() subroutine is not a parsing routine for
Gunnar> general use, but just a part of this particular module.
From past experience, I have seen far too many instances where
people take code like yours "for a specific purpose" and use
it for many other things.
If you didn't write IN BIG BOLD LETTERS next to the example:
NOTE: THESE CODE LINES ARE LIMITED IN THE FOLLOWING WAYS...
then people will copy that stuff.
Bingo. Cargo cult crap.
And in this case, completely avoidable, since CGI.pm would have been
fewer characters to type, easier to explain, more secure, and more
flexible.
There's REALLY NO WIN for a hand-rolled CGI parsing code. Except as I
indicated before... as a teaching exercise, that should be immediately
followed by the CGI.pm example.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sat, 29 Mar 2003 11:00:36 -0500
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <QDmdnZXQasK4XhijXTWcqQ@giganews.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:b63vpg$1fcpn$2@ID-184292.news.dfncis.de...
>
> Hmm.. Taking into consideration that the module does not include any
> multivalue options, how can that be a problem? ;-) As I pointed out
> to Tintin, the readform() subroutine is not a parsing routine for
> general use, but just a part of this particular module.
Frankly, the fact that this is for your "particular module" is completely
irrelevant. If a module is not using CGI.pm, I now have to do additional
research - period. Should I be forced to go to newsgroups to find
discussions like this? If you had used CGI.pm, you would have conferred on
to your script enormous security benefits. You would have made your module
easier for someone else to extend. If 5 years from now CGI is obsolete
(making reading STDIN useless) and you had used CGI.pm, someone will have
ported the new parameter passing system and your script will run untouched.
Plus you have not given a single reason why your custom routine is any
better than using CGI.pm.
--Ben Kennedy
------------------------------
Date: Sat, 29 Mar 2003 18:18:31 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <b64khs$1j9ee$1@ID-184292.news.dfncis.de>
Randal L. Schwartz wrote:
> From past experience, I have seen far too many instances where
> people take code like yours "for a specific purpose" and use
> it for many other things.
>
> If you didn't write IN BIG BOLD LETTERS next to the example:
It is not an example. It is a fragment of Perl code in a module.
> NOTE: THESE CODE LINES ARE LIMITED IN THE FOLLOWING WAYS...
>
> then people will copy that stuff.
>
> Bingo. Cargo cult crap.
Well, I'm not sure if I shall take that seriously...
The consequence of what you say, Randal, is that programming should be
restricted taking into consideration the most ignorant and clueless
people out there, i.e. no code should be used that is not possible to
copy and paste for using also out of its intended context. Let me say
that to me, it's an impossible standpoint.
> CGI.pm would have been fewer characters to type,
True (I think).
> easier to explain,
Why? How?
> more secure,
One reason why I asked for feedback was to test that thesis by giving
people a chance to point out *examples* of security shortcomings.
> and more flexible.
Sure, but the module is not intended to be flexible. Its purpose is to
do one very specific thing.
> There's REALLY NO WIN for a hand-rolled CGI parsing code.
To me it is, since
1) I know what I need to know to do what I do, and
2) I haven't (yet) studied CGI.pm enough to feel comfortable with it.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 29 Mar 2003 18:18:38 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <b64ki3$1j9ee$2@ID-184292.news.dfncis.de>
Ben Kennedy wrote:
> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote:
>>Hmm.. Taking into consideration that the module does not include any
>>multivalue options, how can that be a problem? ;-) As I pointed out
>>to Tintin, the readform() subroutine is not a parsing routine for
>>general use, but just a part of this particular module.
>
> Frankly, the fact that this is for your "particular module" is completely
> irrelevant. If a module is not using CGI.pm, I now have to do additional
> research - period.
Research? Hmm.., maybe I'm beginning to understand what this is about:
Credibility. Maybe it's not at all about making unbiased comparisons
of various coding styles, but only about credibility. At least among
quite a few people in this group, who see a "Matt" in everyone who
don't use CGI. ;-)
> If you had used CGI.pm, you would have conferred on to your script
> enormous security benefits.
Examples, please...
> Plus you have not given a single reason why your custom routine is any
> better than using CGI.pm.
Well, I don't claim that it is. I just believe it's all the same.
Wait, maybe I have, after all. In a reply to Alan I claimed that it's
not advisable - for security reasons - to automatically parse the
querystring, when the info is intended to be POSTed to a program.
For god's sake, we are just talking about a simple reading from STDIN,
aren't we?
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 29 Mar 2003 17:23:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <x7he9m13zv.fsf@mail.sysarch.com>
>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
GH> Also, if you study the program flow, you will notice that the
GH> limitation to accepting POST requests works together with another
GH> security measure, i.e. a referer check to prevent that information is
GH> submitted from anywhere else but the module generated form. (I suppose
GH> this could be handled otherwise, but the check of the REQUEST_METHOD
GH> environment variable is a simple solution.)
you are showing your cgi naivete. all the env values that are passed to
your cgi can be faked by a well written LWP type client. you keep
defending your roll your own but instead you keep showing us why you
shouldn't have done it.
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: Sat, 29 Mar 2003 18:35:56 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <b64lii$1llv0$1@ID-184292.news.dfncis.de>
Uri Guttman wrote:
>>>>>>"GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
> GH> Also, if you study the program flow, you will notice that the
> GH> limitation to accepting POST requests works together with another
> GH> security measure, i.e. a referer check to prevent that information is
> GH> submitted from anywhere else but the module generated form. (I suppose
> GH> this could be handled otherwise, but the check of the REQUEST_METHOD
> GH> environment variable is a simple solution.)
>
> you are showing your cgi naivete. all the env values that are passed to
> your cgi can be faked by a well written LWP type client.
I know that env variables can be faked, Uri, and that a referer check
does not offer any absolute security. (I'm not able to fake it myself,
though.) Nevertheless, making it difficult to send info to a program
in other ways than what's intended, makes it more secure than else
would have been the case. After all, security is also about taking
measures to *reduce* risks, isn't it?
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 29 Mar 2003 13:19:23 -0500
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <96udnVsuw8QxfhijXTWcoQ@giganews.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:b64ki3$1j9ee$2@ID-184292.news.dfncis.de...
> Research? Hmm.., maybe I'm beginning to understand what this is about:
> Credibility. Maybe it's not at all about making unbiased comparisons
> of various coding styles, but only about credibility. At least among
> quite a few people in this group, who see a "Matt" in everyone who
> don't use CGI. ;-)
>
> > If you had used CGI.pm, you would have conferred on to your script
> > enormous security benefits.
>
> Examples, please...
I don't need to give examples because I am not an expert in CGI security.
Yes, the central issue is credibility. CGI.pm is now bundled with Perl, it
has been debugged many times over, is used in thousands of locations, and if
anything hole is discovered, I can update from CPAN. I call this
"credible". If your script parameter parsing was maintained in a similar
way, I'd feel better about using it.
> > Plus you have not given a single reason why your custom routine is any
> > better than using CGI.pm.
>
> Well, I don't claim that it is. I just believe it's all the same.
>
> Wait, maybe I have, after all. In a reply to Alan I claimed that it's
> not advisable - for security reasons - to automatically parse the
> querystring, when the info is intended to be POSTed to a program.
look at the url_param() function in CGI.pm - if you don't even want to
bother parsing it, you could most likely derive from CGI.pm and turn off
that behavior (though I haven't studed the internals)
> For god's sake, we are just talking about a simple reading from STDIN,
> aren't we?
No! This is the point everybody has been trying to make! Good software
design is about modularity and flexibility. Using CGI.pm is good software
design. It is about not making assumptions about there your variables are
coming from, GET or POST.
--Ben Kennedy
------------------------------
Date: 29 Mar 2003 10:14:46 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <86he9mhwfd.fsf@red.stonehenge.com>
*** post for FREE via your newsreader at post.newsfeed.com ***
Addressing only the point that you seem to keep ignoring...
>>>>> "Gunnar" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>> more secure,
Gunnar> One reason why I asked for feedback was to test that thesis by giving
Gunnar> people a chance to point out *examples* of security shortcomings.
A denial of service attack by giving an incredibly long POST. CGI.pm
limits the maximum size of a POST. Your code does not.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
------------------------------
Date: Sat, 29 Mar 2003 19:33:53 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <b64ov7$1o4aj$1@ID-184292.news.dfncis.de>
Ben Kennedy wrote:
> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote:
>
>>> If you had used CGI.pm, you would have conferred on to your
>>> script enormous security benefits.
>>
>> Examples, please...
>
> I don't need to give examples because I am not an expert in CGI
> security.
In that case I think you'd better think twice before making a
statement like that.
> Yes, the central issue is credibility.
Okay. And, believe it or not, that aspect I'm capable to understand.
> Using CGI.pm is good software design. It is about not making
> assumptions about there your variables are coming from, GET or
> POST.
But that I do not understand. How can it always be right to open up
more doors to a system than necessary??
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 29 Mar 2003 14:03:36 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: DBI problem
Message-Id: <3E85EE08.620EC54B@earthlink.net>
Bigus wrote:
>
> Many thanks for your reply. I've placed comments in-line below.
>
> Regards
> Bigus
>
> Benjamin Goldberg wrote:
> [..]
> > > # check if table exists & create it if not
> > > $sth = $db->prepare("SELECT * FROM $groupdb ORDER BY article DESC");
> >
> > Given that you really only want one article, how about:
> >
> > $sth = $db->prepare(qq[
> > SELECT max(article) FROM $groupdb
> > ]);
>
> Thanks, that would be a better way of doing it. One question though..
> Looking at the DBI docs
> (http://www.he.net/info/mysql/dbi.html#Placeholders_and_Bind_Values -
> Performance), for the qq.. syntax it uses curly brackets qq{..}, but above
> you use square brackets. I've not managed to grasp the logic behind the use
> of different types of brackets in Perl yet and I'm still confused! ;-)
Read perldoc perlop, the "Quote-Like Operators" part.
[snip]
> > Is this program being run by a CGI? If so, then there's a race
> > condition -- two difference CGI instances could be accessing this script
> > at the same time, and thus both might end up trying to create the table.
>
> Yes, it's a browser-based news client for a small community on a private
> news server. The Access DB holds the headers of the news posts. I've never
> written a multi-user program before, so I don't know how to get around that
> problem.
Well, for the 'create table' part, writing it as 'create table if not exists'
should suffice -- the Database will handle avoiding a race condition there.
> I was largely hoping that due the predicted usage of it and the
> unlikelihood of actions like creating tables and inserting rows happening at
> exactly the same time that this problem wouldn't crop up and if it did, I
> could fix the DB manually.
> I guess it wouldn't be difficult for me to create a temp file, before the
> table is created or a row is inserted, put a flag in it, then delete the
> file after the action. Then if someone else comes along and tries the same
> thing, the script would check for the presence of the flag and if it finds
> it waits for a period of time.
Unless you create the file using sysopen(), with the O_CREAT|O_EXCL flags,
there's *still* a race condition here.
Oh, and having it wait for a period of time isn't exactly the greatest
thing in the world, since you may end up keeping the connection alive
overly long -- it's ok to sleep for a little while, but if you can't get
the lock quickly enough, have the browser disconnect and try again later.
See:
http://www.stonehenge.com/merlyn/WebTechniques/col54.html
> However, that raises the question of what happens if someone hits the
> stop button their browser and the temp file/flag isn't deleted..
> hmmmm.. if you know any websites that discuss methods of
> locking/queueing processes like this, please let me know.
If you're on *nix, then you can lock a filehandle using flock().
If the process exits, the filehandle is automatically unlocked.
On windows... I'm not sure. However, I believe that Access offers
locking of database tables, through a "LOCK <tablename>" statement.
Make sure that you turn off $dbh->{AutoCommit} before acquiring a lock
using this method.
............
However... You might not *need* to do any such thing -- if, on inserting
your rows, you do something like:
$dbh->do( qq{
INSERT INTO $groupdb
(article, poster, refs, subject, thedate, client, messageid)
VALUES (
(SELECT MAX(article)+1 from $groubdb),
?, ?, ?, ?, ?, ?
)
}, {}, $poster, $refs, $subj, $date, $client, $messageid );
This should, in a single statement, fetch the max article number, add
one to it, and use it for inserting a new row.
... Assuming that that syntax is acceptable to Access. It might not
be. If not, then use a different CREATE TABLE statement, to force
the 'article' field for new rows to come from a sequence:
CREATE TABLE IF NOT EXISTS $groubdb (
article integer NOT NULL DEFAULT nextval('article_seq'),
......
> > > That works fine and therefore the if() block is working.
> > >
> > > If the table does exist then what it's supposed to do is get the
> > > article id ($row[0]) of the first record returned by the original
> > > SELECT statement.
> > > However, it skips the while() block altogether, so the SELECT
> > > statement doesn't appear to be returning any records even though there
> > > are loads in the table.
> >
> > If the 'else' block containing the 'while' block is never entered, then
> > there's a problem.
> >
> > If the 'else' block is entered, but the body of the 'while' block isn't
> > entered, then there's a *different* problem.
>
> Yes, it's the while{} block that isn't entered.
>
> > Without more info, we can't help you.
> >
> > Also, what is $DBI::errstr just below the while loop?
>
> Ahhh, I put the "$sth->err" or whatever it is in there.. that was
> returning -1. Placing $DBI::errstr after the while{} block comes up with
> this:
>
> "[Microsoft][ODBC Microsoft Access Driver]String data, right truncated on
> column number 3 (refs) (SQL-01004)(DBD: st_fetch/SQLFetch (long truncated
> DBI attribute LongTruncOk not set and/or LongReadLen too small) err=-1)"
>
> Yikes! Any idea what that means? Is it something to do with the data in
> column 3? It will either contain one or more references like this
> "b7al8f.1d4.1@hamster.local.invalid#b3aln0.1l4.1@hamster.local.invalid" or a
> space " ".
Obviously, the problem is that it contains a string which is longer than
$dbh->{LongReadLen}. You'll have to increate $dbh->{LongReadLen} to be
at least as long the longest 'ref' field... or, turn on
$dbh->{LongTruncOk}, in which case it will throw away part of the data
without complaining.
A better solution might have been to set up a seperate table for refs,
rather than storing it as a memo field.
This would have been done as:
CREATE TABLE IF NOT EXISTS refs (
article integer NOT NULL REFERENCES $groubdb article,
ref text(255) NOT NULL,
idx integer NOT NULL DEFAULT nextval('ref_id_seq')
)
Thus, for each article, there'd be an ordered set of references, where
each reference is one row in the 'refs' table. (The 'idx' column is
there merely for an 'ORDER BY' clause for your SELECTs.)
Figuring out things like this (knowing to use a seperate table instead
of a memo field) is really a job for a DBA, not truly a perl-specific
task.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 29 Mar 2003 09:30:30 -0800
From: stimonyhall@netscape.net (Upstart)
Subject: Re: implicit vs explicit variable usage in loop w/ range regexp
Message-Id: <79516caa.0303290930.374e01f9@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb89koc.25v.tadmc@magna.augustmail.com>...
> You should always enable warnings when developing Perl code.
oh i did, but the warning did not help me solve the problem... it
drove me toward explicitly setting the variable in the loop, hence why
i am stuck.
JIM
------------------------------
Date: 29 Mar 2003 09:38:13 -0800
From: stimonyhall@netscape.net (Upstart)
Subject: Re: implicit vs explicit variable usage in loop w/ range regexp
Message-Id: <79516caa.0303290938.2b831321@posting.google.com>
yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in message news:<3e84b6e6@news.victoria.tc.ca>...
> This line does not do what you think it does. My added brackets show what
> it is doing.
>
> if ( ($line =~ /^BEGIN:/) ... (/^END:/) ) {
wow. this is not clear to me for the documentation. any manpage i should be reading?
>
> which is of course the same as
>
> if ( ($line =~ /^BEGIN:/) ... ( $_ =~ /^END:/) ) {
>
> which is not what you want.
ok - i'll bite. what do i want? :-)
------------------------------
Date: 29 Mar 2003 15:35:52 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: match all but this
Message-Id: <slrnb8bfao.ang.abigail@alexandra.abigail.nl>
Chris W (idont@thinkso.net) wrote on MMMCDXCVII September MCMXCIII in
<URL:news:yMGcnVrHxt3VPRijXTWcpQ@comcast.com>:
:}
:} "istink" <istink@real.bad.com> wrote in message
:} news:3E850CD7.ACEBDF85@real.bad.com...
:} > how do I match all occurrences of this word but not when its between
:} > these symbols?
:}
:} $a =~ s/([^<].*)red(.*[^>]?)/$1blue$2/gs;
:}
:} I really didn't think this would work, even though Programming Perl hints at
:} it, but I tried it after my last post, and voila! PLEASE do thorough
:} testing, though, as I am VERY new to Perl, and I don't know all the
:} implications of regexes this broad. The script that I tested with was this:
:}
:} $a= '<this is red, but> this is red';
:} $a =~ s/([^<].*)red(.*[^>]?)/$1blue$2/gs;
:} print $a;
But:
$a= 'this is red, but <this is red>';
$a =~ s/([^<].*)red(.*[^>]?)/$1blue$2/gs;
print $a;
prints:
this is red, but <this is blue>
You are basically changing the last 'red' in a string, except if
all that appears before 'red' are '<'s. (.*[^>]?) *always* matches.
([^<].*) matches any non-empty string that doesn't consist solely
of smaller than signs.
Abigail
--
BEGIN {$^H {q} = sub {$_ [1] =~ y/S-ZA-IK-O/q-tc-fe-m/d; $_ [1]}; $^H = 0x28100}
print "Just another PYTHON hacker\n";
------------------------------
Date: 29 Mar 2003 16:03:35 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: match except between...
Message-Id: <slrnb8bgun.ang.abigail@alexandra.abigail.nl>
Chris W (idont@thinkso.net) wrote on MMMCDXCVII September MCMXCIII in
<URL:news:PKSdnS_OVtX6PhijXTWcpA@comcast.com>:
== Okay, I tested this regex in reply to another question in the group:
==
== $a= '<this is red, but> <>this is red too <>';
== $a =~ s/([^<].*)red(.*[^>]?)/$1blue$2/gs;
== print $a;
==
== This is supposed to match the word 'red', as long as it is not enclosed in
== angle brackets, no matter how many other characters are also in the angle
== brackets, and it works great! But...
==
== Can anyone tell me why it matches the second 'red' in the string???
See my other post. Your regex basically matches the *last* 'red' in
a string, except if there are only smaller than signs before that 'red'.
Here's something that does seem to work:
#!/usr/bin/perl
use strict;
use warnings;
my $re = qr /((?:[^<r]+|<[^>]*>|r(?!ed))*|red)/;
while (<DATA>) {
s/$re/$1 eq 'red' ? 'blue' : $1/ge;
print;
}
__END__
This is red and red.
This is <red> and this is red.
This is red and this is <red>.
This is <re> and this is red but this <red> is not.
<This is red> and this is red, but this <is not red at all>.
This gives:
This is blue and blue.
This is <red> and this is blue.
This is blue and this is <red>.
This is <re> and this is blue but this <red> is not.
<This is red> and this is blue, but this <is not red at all>.
It doesn't deal with nested < > though.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: Sat, 29 Mar 2003 09:13:26 -0500
From: "Chris W" <idont@thinkso.net>
Subject: Re: Multiple POSTS and GETS from one perl script
Message-Id: <EEGdnb0QsehANBijXTWc3g@comcast.com>
"Andrew Newlands" <meanblue@rascalsdesign.biz> wrote in message
news:lu6b8v464670mhnkh194apep2ont1j8376@4ax.com...
> I am trying to find out how I can POST data from one perl(A) script to
> another perl script(B)without leaving the original script (A) and
> allowing it to continue processing.
>
> To put this in a practical example, a script POSTS data calculated to
> a script that alters a database, but then POSTS to another script to
> display what the user should see.
>
> Can any one help?
Just send a redirect to the browser, and add the parameters you want to the
URL:
http://mysite.com/cgi-bin/paramtest.pl?parm1=this&parm2=that&nextparm=theoth
er
------------------------------
Date: Sat, 29 Mar 2003 14:37:51 +0000
From: Andrew Newlands <meanblue@rascalsdesign.biz>
Subject: Re: Multiple POSTS and GETS from one perl script
Message-Id: <gpbb8vg529dfe10a4dg7krvtlvjj7laoau@4ax.com>
On Sat, 29 Mar 2003 09:13:26 -0500, "Chris W" <idont@thinkso.net>
wrote:
>
>"Andrew Newlands" <meanblue@rascalsdesign.biz> wrote in message
>news:lu6b8v464670mhnkh194apep2ont1j8376@4ax.com...
>> I am trying to find out how I can POST data from one perl(A) script to
>> another perl script(B)without leaving the original script (A) and
>> allowing it to continue processing.
>>
>> To put this in a practical example, a script POSTS data calculated to
>> a script that alters a database, but then POSTS to another script to
>> display what the user should see.
>>
>> Can any one help?
>
>
>Just send a redirect to the browser, and add the parameters you want to the
>URL:
>
>http://mysite.com/cgi-bin/paramtest.pl?parm1=this&parm2=that&nextparm=theoth
>er
>
Yes this would work and is what I at present am doing - however I was
wondering if there is a way of posting data to other scripts while
continuing to run the original script, branching off so that 2 scripts
are runnning on the webserver as opposed to one.
Can a script be executed without the use of a browser? - surely you
can post data to a script on a webserver without the users browser
opening it? or am I wrong...
------------------------------
Date: Sat, 29 Mar 2003 15:48:46 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Multiple POSTS and GETS from one perl script
Message-Id: <b64bp3$1i67a$1@ID-184292.news.dfncis.de>
Andrew Newlands wrote:
> I was wondering if there is a way of posting data to other scripts
> while continuing to run the original script, branching off so that
> 2 scripts are runnning on the webserver as opposed to one.
It sounds to me as if you should start studying how to send data to
another script via a HTTP request. This is a script of mine that does
just that: http://www.gunnar.cc/mhonarc/mailfwd.pl.txt
I used the LWP::UserAgent module, but I suppose that there are other
methods.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 29 Mar 2003 10:02:28 -0500
From: "Chris W" <idont@thinkso.net>
Subject: Re: Multiple POSTS and GETS from one perl script
Message-Id: <V9CcnauotofGKBijXTWcoA@comcast.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:b64bp3$1i67a$1@ID-184292.news.dfncis.de...
> Andrew Newlands wrote:
> > I was wondering if there is a way of posting data to other scripts
> > while continuing to run the original script, branching off so that
> > 2 scripts are runnning on the webserver as opposed to one.
>
> It sounds to me as if you should start studying how to send data to
> another script via a HTTP request. This is a script of mine that does
> just that: http://www.gunnar.cc/mhonarc/mailfwd.pl.txt
>
> I used the LWP::UserAgent module, but I suppose that there are other
> methods.
Thanks for the code example.. I learn more from code like this than from an
hour reading books.
------------------------------
Date: Sat, 29 Mar 2003 15:02:58 +0000
From: Andrew Newlands <meanblue@rascalsdesign.biz>
Subject: Re: Multiple POSTS and GETS from one perl script
Message-Id: <ocdb8v4gfpmkpddkk0pra0dcmavmp20d48@4ax.com>
On Sat, 29 Mar 2003 10:02:28 -0500, "Chris W" <idont@thinkso.net>
wrote:
>
>"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
>news:b64bp3$1i67a$1@ID-184292.news.dfncis.de...
>> Andrew Newlands wrote:
>> > I was wondering if there is a way of posting data to other scripts
>> > while continuing to run the original script, branching off so that
>> > 2 scripts are runnning on the webserver as opposed to one.
>>
>> It sounds to me as if you should start studying how to send data to
>> another script via a HTTP request. This is a script of mine that does
>> just that: http://www.gunnar.cc/mhonarc/mailfwd.pl.txt
>>
>> I used the LWP::UserAgent module, but I suppose that there are other
>> methods.
>
>Thanks for the code example.. I learn more from code like this than from an
>hour reading books.
>
>
Cheers - will havea look thro :)
------------------------------
Date: Sat, 29 Mar 2003 09:53:58 -0500
From: "Chris W" <idont@thinkso.net>
Subject: Re: Perl and Objects (kinda OT)
Message-Id: <4-ScnT3ZMILALhijXTWc3A@comcast.com>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message
news:b63j4f$kge$1@nets3.rz.RWTH-Aachen.DE...
> multiple-inheritance, operator overloading etc). Some other things are
> specific to Perl (I think), such as lvaluable methods (these are methods
> that you can assign a value to)
C++ does this too. All you do is return a reference to an lvalue from the
method, and it is legal on the left side of an assignment.
------------------------------
Date: Sat, 29 Mar 2003 12:58:32 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Perl and objects
Message-Id: <3E85ECD8.3090309@annuna.com>
I have been looking a simple object in the programming perl book. I
think I wrote a simple class. It is a simple player class that will
have his name and x and y location for walking on a simple map.
#!/user/bin.perl
use strict;
my $n;
sub player {
my $char = {};
my $self;
$char -> name()
$char -> xcord();
$char -> ycord();
bless $self, $char;
return $char;
}
print "Your name sir:";
$n = <STDIN>;
** -> player ($char{name(->$n}); <-**
The marked spot is where I am having trouble. I created a simple class
and a few objects in C++ but here seems very different.
Once I figure out how to work with objects I will write the rest of the
code.
------------------------------
Date: Sat, 29 Mar 2003 09:23:35 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Re: Perl and Objects
Message-Id: <3E85BA77.8080307@annuna.com>
Tassilo v. Parseval wrote:
> Also sprach Joe Creaney:
>
>
>>I have been reading and learning C++ and Perl. I prefer to work in Perl
>>is a much friendlier language. I just find creating classes and objects
>> in C++ much more strait forward. It might just be the difference in
>>refrences I have. I just find all the examples in perl very confusing
>>when I am still confused with objects in general. Could I get a realy
>>simple example of a program that creates a class may be one attribue and
>> one method. From that Make two objects that do something in a realy
>>simple program.
>
>
Thank you so much for this example. It is exactly what I was looking
for. I just hadn't seen all the parts in one place and how they work
together. I will save this example and play with it so I better
understand the concepts and to actually do something in this programming
style.
------------------------------
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 4783
***************************************