[21716] in Perl-Users-Digest
Perl-Users Digest, Issue: 3920 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 5 14:11:20 2002
Date: Sat, 5 Oct 2002 11:10:14 -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, 5 Oct 2002 Volume: 10 Number: 3920
Today's topics:
Re: Novice - Submit to different scripts <flavell@mail.cern.ch>
Re: Novice - Submit to different scripts (Tad McClellan)
Re: One line to Segfault Perl (Mark Jason Dominus)
Re: Script to Change Filename (Tad McClellan)
Re: Script to Change Filename <wsegrave@mindspring.com>
Re: Script to Change Filename <wsegrave@mindspring.com>
Re: Script to Change Filename (Tad McClellan)
Re: Script to Change Filename (Walter Roberson)
Re: Send email from a Database Management Script <jhammock@molalla.net>
Re: What can I do if I have not got chmop <REMOVEsdnCAPS@comcast.net>
Re: What does [^\n] mean (david rayner)
Re: What does [^\n] mean <No_Mail_Address@cox.net>
Re: What does [^\n] mean <No_Mail_Address@cox.net>
Re: What does [^\n] mean <krahnj@acm.org>
Re: What does [^\n] mean (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 5 Oct 2002 13:32:12 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Novice - Submit to different scripts
Message-Id: <Pine.LNX.4.40.0210051313030.20097-100000@lxplus076.cern.ch>
On Oct 4, Lew903 inscribed on the eternal scroll:
[...sniporama...]
> I respectfully ask for your suggestions on a method for getting one
> Submit (Continue) button to call different scripts based on
> conditionals.
This is a CGI question (such questions would be more on-topic on
comp.infosystems.www.authoring.cgi - check its posting guidelines)
but in fact is an FAQ there.
The answer is that an HTML FORM has an ACTION URL, and that specifies
the process (script etc.) which will field the form submission. That
URL is fixed when the FORM is written, i.e you can configure it on the
basis of what you got from previous forms if you're writing a new form
for each submission cycle, but when your form is written, it's fixed.
What you do in that script is up to you.
> I'd like to do this without using JavaScript
Of course, since javascript is optional..
> The first thing that comes to my uneducated mind is have the submit
> button call an intermediate script that calls the appropriate script
> based on the radio buttons selected.
Bingo. But why do you suppose these have to be different "scripts"
behind such a CGI wrapper? It's only a question of how you organise
your code.
Or are you trying to say that someone has given you some pre-written
CGI scripts and you want to invoke those without modifying them? That
way lies various kinds of maintenance nightmare IMHO.
> Other questions, such as what to
> do about responding to the browser in the intermediate script, have me
> at a loss at this point.
If they do that for you, just how do you suppose your users - who
don't know anything about what's going in behind the scenes - are
liable to be confused? Many, many forms-based procedures on the WWW
have (in my observations) been cobbled-up in a way that thoroughly
confuses the user (not only simple things like demanding yes/no
answers to questions that are not applicable; ZIPcodes in USA format
for Canadian applicants; insisting that European users enter their
phone number as 1-xxx-xxx-xxxx), and suggests that their author was
even more confused than the user about what they were implementing.
Don't over-reach yourself: my advice would be to implement something
simple that's comfortably within your capabilities, then at least it
should have a chance of not painting the user into impossible corners.
Have fun.
------------------------------
Date: Sat, 5 Oct 2002 07:25:53 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Novice - Submit to different scripts
Message-Id: <slrnaptmih.4s3.tadmc@magna.augustmail.com>
Lew903 <lsuttles@lcsdg.com> wrote:
> I respectfully ask for your suggestions on a method for getting one
> Submit (Continue) button to call different scripts based on
> conditionals.
I suggest that you do not call different scripts
based on conditionals. :-)
> The first thing that comes to my uneducated mind is have the submit
> button call an intermediate script that calls the appropriate script
> based on the radio buttons selected.
Rewrite the "appropriate script"s as subroutines. Have one CGI
program that calls the applicable subroutine(s).
> Other questions, such as what to
> do about responding to the browser in the intermediate script, have me
> at a loss at this point.
You need only send output to STDOUT. If the "appropriate script"
makes the correct output, the browser will be happy, even if
the program was called from within some other program.
It doesn't matter what program makes the output on STDOUT,
only that it gets made one way or another.
> Any input much appreciated, Lewis
Since you mention that you are new to all of this, let me point out
two Very Important Things that you have made no mention of.
Spoofing hidden fields is childishly easy, you better enable
"taint checking" on all CGI programs that accept user input
(hidden fields *are* user input):
perldoc perlsec
You will need to use file locking if you want to avoid corrupted data:
perldoc -q "\block"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 5 Oct 2002 14:49:16 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: One line to Segfault Perl
Message-Id: <anmu5c$agk$1@plover.com>
In article <x7adlut460.fsf@mail.sysarch.com>,
Uri Guttman <uri@stemsystems.com> wrote:
>but you have to ask the question wtf execute 'undef tcp'?
Maybe you have to ask that; I don't.
I once reported that Perl dumped core when I gave it a uuencoded file
as input.
------------------------------
Date: Sat, 5 Oct 2002 07:50:21 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Script to Change Filename
Message-Id: <slrnapto0d.4s3.tadmc@magna.augustmail.com>
Harald H.-J. Bongartz <bongie@gmx.net> wrote:
> William Alexander Segraves wrote:
>> s/^((?:\d){3,8})([a-zA-Z]\.dat)$/${1}-${2}/; #regex from David
> ^^^^^^
> Could someone please explain to me why this strange complication of \d
> is occuring repeatedly in this thread?
No, because it is not needed at all.
s/^(\d{3,8})([a-zA-Z]\.dat)$/${1}-${2}/;
will behave exactly the same.
I do not know why it was introduced (he said it was "late" :-),
but it hasn't occurred "repeatedly". Just the once, then
quoted a few times and left in when reworked.
> I cannot see the advantage of
> '((?:\d){3,8})' compared with '(\d{3,8})', as suggested by others.
There is no advantage. It is spurious.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 5 Oct 2002 10:59:25 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Script to Change Filename
Message-Id: <ann3oh$ju7$1@slb7.atl.mindspring.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnapto0d.4s3.tadmc@magna.augustmail.com...
> Harald H.-J. Bongartz <bongie@gmx.net> wrote:
> > William Alexander Segraves wrote:
> >> s/^((?:\d){3,8})([a-zA-Z]\.dat)$/${1}-${2}/; #regex from David
> > ^^^^^^
> > Could someone please explain to me why this strange complication of \d
> > is occuring repeatedly in this thread?
>
>
> No, because it is not needed at all.
>
> s/^(\d{3,8})([a-zA-Z]\.dat)$/${1}-${2}/;
>
> will behave exactly the same.
>
Thanks, Tad. I'll fix _my_ version of _my_ script. When I introduced your
suggested changes for the OP's "new" spec, I made no other changes to David
Britten's regex from the much earlier thread:
For clarity:
DB wrote: "I should really be in bed right now, so hopefully I don't mess
this up. :-)
Assuming you're reading the filenames one at a time into a variable called
$filename, then try this regexp:
$newname = $filename
$success = $newname =~ s/((?:\d)+)([a-zA-Z]\.dat)/${1}-${2}/;
..."
The above regex is what I used first, before trying suggestions from others,
except yours. It appeared to meet the original spec, i.e., one or more
digits + a lc character a-z + filename extension .dat. In fact, it did not.
You pointed out one example that was spuriously converted. A little while
ago, I found 123a456b.dat to be spuriously converted to 123a456-b.dat.
Adding the anchors you suggested to David Britten's regex makes it work
correctly for the original spec.
In summary, the responsibility for the implementation of your suggestions in
David Britten's regex was mine. Indeed, I may have erred in providing
(leaving in the regex) something that is not needed at all (for the new
spec).
>
> I do not know why it was introduced (he said it was "late" :-),
If "he" is "I", I should have said it was _very_ late. ;-)
> but it hasn't occurred "repeatedly". Just the once, then
> quoted a few times and left in when reworked.
>
Thanks for cutting me a little slack.
>
> > I cannot see the advantage of
> > '((?:\d){3,8})' compared with '(\d{3,8})', as suggested by others.
>
>
> There is no advantage. It is spurious.
Perhaps someone can explain what it means in the context of
1. _Perl in a Nutshell_, 1st ed. p. 69, "Extended Regular Expressions"
(?:...)
This groups things like "(...)" but doesn't make backreferences.
or
2. _Programming Perl_, 2nd ed., p. 57-76, Pattern Matching, p. 91,
"Conditional Operator".
It would also be helpful if David Britten would tell us why he used ?: in
the regex in his original post.
In summary, Harold, the reason for unnecessary use of ?: in the original
regex from David Britten eludes me, too. I propagated it in my posts because
I didn't know it was not needed until I tried the other suggestions.
Cheers.
Bill Segraves
------------------------------
Date: Sat, 5 Oct 2002 11:25:01 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Script to Change Filename
Message-Id: <ann3oi$ju7$2@slb7.atl.mindspring.net>
"William Alexander Segraves" <wsegrave@mindspring.com> wrote in message
news:anm2qs$1s6$1@slb6.atl.mindspring.net...
> "JP" <NO_SPAM_pangjoe@rogers.com> wrote in message
> news:Mgtn9.20894$Aiq1.19462@news04.bloor.is.net.cable.rogers.com...
> <snip>
Joe P. (OP):
Please replace the script in the previous post with the following, modified
to eliminate David Britten's use of ?: in the regex:
#!perl -w
# filedasher_v6.pl- adds dashes into filenames, e.g., 12345a.dat becomes
12345-a.dat
use strict;
my $dir = 'c:\indigoperl\tmp'; #my path
opendir (DIR, $dir) or die "Cannot locate directory $dir:$!\n";
foreach (readdir DIR) {
my $old = $_;
s/^(\d{3,8})([a-zA-Z]\.dat)$/${1}-${2}/; # regex from David Britten,
modified by Tad McClellan
my $new = $_;
unless ($old eq $new){
print "Renaming $old to $new\n";
rename ($old, $new) || warn "Can't rename $old to $new: $!";
}
}
As usual, watch out for the line wraps introduced by Outlook Express if you
copy and paste.
Thanks again to David, Harold, Helgi, Jue, Steve, Tad, Tina, et al, for
useful comments.
Cheers.
Bill Segraves
------------------------------
Date: Sat, 5 Oct 2002 12:03:24 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Script to Change Filename
Message-Id: <slrnapu6qs.20d.tadmc@magna.augustmail.com>
William Alexander Segraves <wsegrave@mindspring.com> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnapto0d.4s3.tadmc@magna.augustmail.com...
>> Harald H.-J. Bongartz <bongie@gmx.net> wrote:
>> > William Alexander Segraves wrote:
>> >> s/^((?:\d){3,8})([a-zA-Z]\.dat)$/${1}-${2}/; #regex from David
> Perhaps someone can explain what it means in the context of
( "it" being non-capturing parenthesis)
> 1. _Perl in a Nutshell_, 1st ed. p. 69, "Extended Regular Expressions"
>
> (?:...)
> This groups things like "(...)" but doesn't make backreferences.
Parenthesis in patterns do _two_ things, they give you grouping
and they "remember" the characters that matched that part of
the pattern.
If you need it for grouping only, it still "counts" when
determining the backref positions.
If we used "plain" parens instead:
s/^((\d){3,8})([a-zA-Z]\.dat)$/${1}-${3}/;
^
^
we would need to adjust all backref numbers.
(?: ) gives you grouping but does not give you memory, leaving
the counts unsullied.
(and it is not "?:" that we are talking about here. The token
is all three characters "(?:" together.
)
> 2. _Programming Perl_, 2nd ed., p. 57-76, Pattern Matching, p. 91,
> "Conditional Operator".
#2 is not at all the same operator!
It is not related to pattern matching in any way.
It is called ?: because it doesn't have a handy name[1]. It never
actually appears that way, because you put something (the
"true" case) in between the question mark and the colon.
[1] I call it the "ugly 3-part C-like thingie", and resort to
its use only in a very few situations.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 5 Oct 2002 17:31:23 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: Script to Change Filename
Message-Id: <ann7lb$7jp$1@canopus.cc.umanitoba.ca>
In article <slrnapu6qs.20d.tadmc@magna.augustmail.com>,
Tad McClellan <tadmc@augustmail.com> wrote:
:It is called ?: because it doesn't have a handy name[1].
:[1] I call it the "ugly 3-part C-like thingie", and resort to
: its use only in a very few situations.
It's usually called "question-colon", at least in a C / C++ context.
--
We don't need no side effect-ing
We don't need no scope control
No global variables for execution
Hey! Did you leave those args alone? -- decvax!utzoo!utcsrgv!roderick
------------------------------
Date: Sat, 05 Oct 2002 08:57:58 -0700
From: Jeffery D Hammock <jhammock@molalla.net>
Subject: Re: Send email from a Database Management Script
Message-Id: <av2upu0ra2i1cag60h86cjusr2vl7err88@4ax.com>
WZOn 2 Oct 2002 02:46:54 -0700, prometheus_au@excite.com.au (Dave)
wrote:
>G'day all...
>
>I have a flat-file pipe delimted contact database, which is used by
>several scripts on my site. I'm wondering if anyone knows of a
>database management script which will allow the 'admin' (via an HTML
>interface) to choose a contact and send an email (preformatted or
>otherwise) to only the contact chosen?
>
>I've been searching and found nothing yet. Any help would be
>appreciated.
>
>Cheers
>Dave.
>
>to reply directly change "excite" to "optusnet" - gotta keep them
>spambots confused!
------------------------------
Date: Sun, 06 Oct 2002 05:16:31 CDT
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: What can I do if I have not got chmop
Message-Id: <Xns929E718BB2C5Dsdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Steve Grazzini <s_grazzini@hotmail.com> wrote in news:Whon9.37699
$YI.7918175@twister.nyc.rr.com:
> Nigel Goldsmith <nigel@bannockfarm.freeserve.co.uk> wrote:
>> Wrote a little bit of code on perl 5 then took it on to an old Sun
>> box and it did not like chomp, are there any alternatives? I am
>> sure there are let the code flow!!!
>
> There is *no way* to do it.
>
> You have to upgrade. :)
>
>
> [ tested only on 5.8 ]
>
> sub chomp {
> return 0 unless defined $/;
Didn't perl4 require parentheses? "defined($/)" ?
> if (length $/) {
> foreach (@_ ? @_ : $_) { $ret += s|$/$|| }
And I'm *sure* perl4 did not handle arrays in ?: constructs.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPZ8AtWPeouIeTNHoEQI/2QCg1IxWzxRuCLMDlBdr974D2t9NnogAn131
/fI7QuMF9sgMC27YpTHcA6nA
=r1fL
-----END PGP SIGNATURE-----
------------------------------
Date: 5 Oct 2002 04:55:14 -0700
From: david@tvis.co.uk (david rayner)
Subject: Re: What does [^\n] mean
Message-Id: <f677762.0210050355.bfa4300@posting.google.com>
Fred <No_Mail_Address@cox.net> wrote in message news:<3D9E87E9.E3068570@cox.net>...
> The following code is from a script for cleaning mailfiles, it removes
> the (multiline) "Received:" sections:
>
> ....
> $/ = undef;
> while (<INPUT>) {
> s/^(Received:\s[^\n]+\n)(\s+[^\n]+\n)*//mg;
> print OUTPUT $_,"\n";
> }
> .....
>
> My problem is that I cannot understand how it works. I made searches
> for [^\n] and ^\n in the CSPAN-manual and in Perl book CD-ROM's but
> could not find anything useful. Also I thought that with $/ = undef;
> all \n are removed.
In side a range ^ means not. So [^\n]+ means as many non-carriage
returns as possible
------------------------------
Date: Sat, 05 Oct 2002 13:54:23 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Re: What does [^\n] mean
Message-Id: <3D9EEF2F.9658FD23@cox.net>
Tan Nguyen wrote:
>
> "Fred" <No_Mail_Address@cox.net> wrote in message
> news:3D9E87E9.E3068570@cox.net...
> > The following code is from a script for cleaning mailfiles, it removes
> > the (multiline) "Received:" sections:
> >
<snipped>
> >
>
> Quick explanation....It means "not newline". The substitution says -
> substitute a string starting(^) with Received: followed by a space (\s) and
> anything that isn't a newline ([^\n])+ and then a newline ....and so on with
> an empty string.
>
> Setting $/ to undef (local $/ = undef) will only change the _input_ record
> separator (for example, when you read in a file).
Thank you Tan, now I got it...
--
Fred
------------------------------
Date: Sat, 05 Oct 2002 14:02:03 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: Re: What does [^\n] mean
Message-Id: <3D9EF0FB.30303B92@cox.net>
david rayner wrote:
>
> Fred <No_Mail_Address@cox.net> wrote in message news:<3D9E87E9.E3068570@cox.net>...
<snip>
>> I made searches for [^\n] and ^\n in the CSPAN-manual
>> and in Perl book CD-ROM's but could not find anything useful.
>> Also I thought that with $/ = undef; all \n are removed.
> In side a range ^ means not. So [^\n]+ means as many non-carriage
> returns as possible
Thank you David.
--
Fred
------------------------------
Date: Sat, 05 Oct 2002 14:06:21 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: What does [^\n] mean
Message-Id: <3D9EF1D2.D14E12EE@acm.org>
Fred wrote:
>
> The following code is from a script for cleaning mailfiles, it removes
> the (multiline) "Received:" sections:
>
> ....
> $/ = undef;
> while (<INPUT>) {
> s/^(Received:\s[^\n]+\n)(\s+[^\n]+\n)*//mg;
> print OUTPUT $_,"\n";
> }
> .....
>
> My problem is that I cannot understand how it works. I made searches
> for [^\n] and ^\n in the CSPAN-manual and in Perl book CD-ROM's but
> could not find anything useful. Also I thought that with $/ = undef;
> all \n are removed.
[^\n]+ means to match one or more characters that is not a newline
character which is the same as .+ when the /s option is not used. The
substitution operator appears to be removing Received lines from e-mail
headers which can span more than one physical line. The capturing
parentheses aren't required if that is all it is doing.
s/^Received:\s.+\n(?:\s+.+\n)*//mg;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 5 Oct 2002 12:18:15 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What does [^\n] mean
Message-Id: <slrnapu7mn.20d.tadmc@magna.augustmail.com>
Fred <No_Mail_Address@cox.net> wrote:
> Also I thought that with $/ = undef;
> all \n are removed.
What made you think that?
Did you read it somewhere?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
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 3920
***************************************