[19923] in Perl-Users-Digest
Perl-Users Digest, Issue: 2118 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 12 18:11:00 2001
Date: Mon, 12 Nov 2001 15:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005606610-v10-i2118@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 12 Nov 2001 Volume: 10 Number: 2118
Today's topics:
RegEx problem -- trying to match To: or From: at beginn <donotspam-jen@dangerousideas.com>
Re: RegEx problem -- trying to match To: or From: at be <Tassilo.Parseval@post.rwth-aachen.de>
Re: RegEx problem -- trying to match To: or From: at be (Chas Friedman)
Re: RegEx problem -- trying to match To: or From: at be <bart.lateur@skynet.be>
Re: RegEx problem -- trying to match To: or From: at be <donotspam-jen@dangerousideas.com>
Re: RegEx problem -- trying to match To: or From: at be (Garry Williams)
Re: RegEx problem -- trying to match To: or From: at be <bart.lateur@skynet.be>
Re: RegEx problem -- trying to match To: or From: at be <godzilla@stomp.stomp.tokyo>
Re: Reserve memory for array? <Tassilo.Parseval@post.rwth-aachen.de>
Re: self-printing perl program <godzilla@stomp.stomp.tokyo>
Re: starting perl <mgjv@tradingpost.com.au>
Re: Unencoding <mgjv@tradingpost.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 12 Nov 2001 12:00:08 -0800
From: "jennyw" <donotspam-jen@dangerousideas.com>
Subject: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <9sp9l3$j6b$1@bob.news.rcn.net>
I'm using Perl to match certain message headers (To: and From:). I thought
this regex would work:
/^(To)|(From)/
Unfortunately, not only does this match lines that begin with To: or From:,
but it also matches lines that being with Reply-To. Why is this? I thought
having the ^ at the beginning meant that it would have to be at the
beginning of the line?
Thanks!
Jen
------------------------------
Date: Mon, 12 Nov 2001 21:09:25 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <9spa9l$4d7$02$1@news.t-online.com>
On Mon, 12 Nov 2001 12:00:08 -0800, jennyw wrote:
> I'm using Perl to match certain message headers (To: and From:). I thought
> this regex would work:
>
> /^(To)|(From)/
>
> Unfortunately, not only does this match lines that begin with To: or From:,
> but it also matches lines that being with Reply-To. Why is this? I thought
> having the ^ at the beginning meant that it would have to be at the
> beginning of the line?
No, the above regex does not match 'Reply-to' header-fields. May it be
that you had in fact written /^(From)|(To)/ ?
However, if you seperate alternative patterns with '|' you have to use
anchors for both of them. A correct pattern for these header-fields
would therefore look like:
if ( /^From: (.*)|^To: (.*)/ ) { print "Data: $1" }
Tassilo
--
Coach: What's up, Norm?
Norm: Corners of my mouth, Coach.
-- Cheers, Fortune and Men's Weights
Coach: What's shaking, Norm?
Norm: All four cheeks and a couple of chins, Coach.
-- Cheers, Snow Job
Coach: Beer, Normie?
Norm: Uh, Coach, I dunno, I had one this week. Eh, why not, I'm still young.
-- Cheers, Snow Job
------------------------------
Date: Mon, 12 Nov 2001 20:16:51 GMT
From: friedman@math.utexas.edu (Chas Friedman)
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <3bf02ccd.58387537@news.itouch.net>
On Mon, 12 Nov 2001 12:00:08 -0800, "jennyw"
<donotspam-jen@dangerousideas.com> wrote:
>I'm using Perl to match certain message headers (To: and From:). I thought
>this regex would work:
>
>/^(To)|(From)/
>
>Unfortunately, not only does this match lines that begin with To: or From:,
>but it also matches lines that being with Reply-To. Why is this? I thought
>having the ^ at the beginning meant that it would have to be at the
>beginning of the line?
>
>Thanks!
>
>Jen
>
Try
/^To: / or /^From: /
Incidentally, you may have to worry about the fact that an email
might contain other lines beginning with "From" or "To". Emails
usually begin with a header "From ...". The sender usually is on a
line beginning with "From: " There may also be lines in the body of
the email beginning with "From " or "To ".
cf
------------------------------
Date: Mon, 12 Nov 2001 20:44:40 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <c1d0vt4uee903j4pcmlhjo2egkiliopn35@4ax.com>
jennyw wrote:
>I'm using Perl to match certain message headers (To: and From:). I thought
>this regex would work:
>
>/^(To)|(From)/
>
>Unfortunately, not only does this match lines that begin with To: or From:,
>but it also matches lines that being with Reply-To. Why is this?
Likely because your regex is actually
/^(From)|(To)/
The ^ is taken as part of the first alternative. You need parens to put
it outside the grouping, or repeat it:
/^(From|To)/
or
/^From|^To/
If you don't need the capturing effect of the parentheses, you can use
(?:...) instead:
/^(?:From|To)/
--
Bart.
------------------------------
Date: Mon, 12 Nov 2001 12:48:59 -0800
From: "jennyw" <donotspam-jen@dangerousideas.com>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <9spcgl$su1$1@bob.news.rcn.net>
Actually, I realized the problem. I need to use:
/(^To:)|(^From:)/
I'm not sure why the carets (^) need to be inside the parentheses, but it
works this way.
What I'm actually trying to determine is whether or not the header line is
one of the ones I'm interested in (only From: or To:). I'm using IMAP to
get the headers, so no other lines will begin this way.
Thanks!
Jen
"Chas Friedman" <friedman@math.utexas.edu> wrote in message
news:3bf02ccd.58387537@news.itouch.net...
> On Mon, 12 Nov 2001 12:00:08 -0800, "jennyw"
> <donotspam-jen@dangerousideas.com> wrote:
>
> >I'm using Perl to match certain message headers (To: and From:). I
thought
> >this regex would work:
> >
> >/^(To)|(From)/
> >
> >Unfortunately, not only does this match lines that begin with To: or
From:,
> >but it also matches lines that being with Reply-To. Why is this? I
thought
> >having the ^ at the beginning meant that it would have to be at the
> >beginning of the line?
> >
> >Thanks!
> >
> >Jen
> >
> Try
> /^To: / or /^From: /
> Incidentally, you may have to worry about the fact that an email
> might contain other lines beginning with "From" or "To". Emails
> usually begin with a header "From ...". The sender usually is on a
> line beginning with "From: " There may also be lines in the body of
> the email beginning with "From " or "To ".
> cf
------------------------------
Date: Mon, 12 Nov 2001 20:50:06 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <slrn9v0dg0.2rp.garry@zfw.zvolve.net>
On Mon, 12 Nov 2001 12:00:08 -0800, jennyw
<donotspam-jen@dangerousideas.com> wrote:
> I'm using Perl to match certain message headers (To: and From:). I thought
> this regex would work:
>
> /^(To)|(From)/
That will match any string that begins with `To' or any string that
*contains* `From'. It will capture in $1 nothing or `To' and in $2
`From' or nothing if there was actually a match.
> Unfortunately, not only does this match lines that begin with To: or From:,
> but it also matches lines that being with Reply-To.
I don't believe you:
$ perl -wle 'print "matched" if "Reply-To" =~ /^(To)|(From)/'
$ perl -wle 'print "matched" if "To" =~ /^(To)|(From)/'
matched
$
> Why is this? I thought
> having the ^ at the beginning meant that it would have to be at the
> beginning of the line?
You probably want
/^To: |^From: /
assuming that the strange capture wasn't really necessary.
--
Garry Williams
------------------------------
Date: Mon, 12 Nov 2001 21:05:35 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <ice0vt0b5g4211bgk5k1fq74q1g7ei7bfc@4ax.com>
jennyw wrote:
>Actually, I realized the problem. I need to use:
>
>/(^To:)|(^From:)/
>
>I'm not sure why the carets (^) need to be inside the parentheses, but it
>works this way.
They don't. This works too:
/^(To:)|^(From:)/
--
Bart.
------------------------------
Date: Mon, 12 Nov 2001 13:49:03 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <3BF043CF.7A8D8187@stomp.stomp.tokyo>
jennyw wrote:
> I'm using Perl to match certain message headers (To: and From:). I thought
> this regex would work:
> /^(To)|(From)/
> Unfortunately, not only does this match lines that begin with To: or From:,
> but it also matches lines that being with Reply-To.
(snipped)
You have failed to provide clear and concise parameters. This is
a dangerous idea. There is no indication if you are processing
your email file one line at a time or, treating your email file
as a single string.
Any answers provided are only wild guesses due to your failure
to communicate effectively and efficiently.
This is my wild guess based on line-by-line reading.
if (substr ($email_line, 0, 3) eq "To:")
{ Do Something; }
if (substr ($email_line, 0, 5) eq "From:")
{ Do Something; }
Use of a regex for a such a simple task as yours, is an
equally dangerous idea.
Godzilla! Queen Of Dangerous Ideas.
------------------------------
Date: Mon, 12 Nov 2001 20:50:54 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Reserve memory for array?
Message-Id: <9sp96u$mnk$06$1@news.t-online.com>
On Mon, 12 Nov 2001 17:38:37 GMT, Mark Jason Dominus wrote:
> In article <9sn59a$85a$07$1@news.t-online.com>,
> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote:
>>It may be more efficient but that's debatable. There is the trick of
>>assigning to $#array.
>>
>>my @a;
>>$#a = 10000000;
>>
>>This eats about 40meg of memory on my machine. You can experiment a
>>little with the number. According to top '$#a = 2500000;' needs quite
>>exactly 10meg.
>
> You may want to point out that while that reserves 10M for the array,
> it reserves 0 for the data that will be stored *in* the array.
>
> I expect that Markus is asking The Wrong Question here.
I suppose he wants to avoid that new blocks of memory have to be
allocated when the size of the array passes a certain threshold.
On the other hand this extra amount of reserved memory could make a
system swap earlier (it certainly does when no longer any physical RAM
is available) which in turn would slow down other processes. So you are
probably right in suspecting that this may be the wrong approach to a
speed-optimization of a Perl script.
As for the zero meg of memory reserved for the data, I can't say much
about that since I don't exactly know how Perl organizes the data stored
in an array or a hash. I suppose it uses several layers of pointers
pointing to the respective SV.
Tassilo
--
I find this corpse guilty of carrying a concealed weapon and I fine it $40.
-- Judge Roy Bean, finding a pistol and $40 on a man he'd
just shot.
------------------------------
Date: Mon, 12 Nov 2001 12:48:32 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: self-printing perl program
Message-Id: <3BF035A0.4B0174AC@stomp.stomp.tokyo>
Charles Blair wrote:
> I'm sure this must be an FAQ, but I couldn't find it in admittedly
> cursory searching. What is the shortest perl program that will
> print itself? I suspect something can be done with eval, but haven't
> figured out what.
Godzilla!
--
#!perl
seek (DATA, 0, 0);
print <DATA>;
__DATA__
------------------------------
Date: Mon, 12 Nov 2001 22:39:12 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: starting perl
Message-Id: <slrn9v0jt8.2q5.mgjv@verbruggen.comdyn.com.au>
On 12 Nov 2001 13:38:19 +0100,
Måns Rullgård <mru@users.sf.net> wrote:
> What is the right way to execute a perl script with the first perl in
> PATH? Since perl will run whatever is on a #! line things like
> #!/bin/sh
> #\
> exec perl $0 $*
I think you are looking for the stuff described in the perlrun manual
page:
$ man perlrun
[SNIP]
Parsing of the #! switches starts wherever "perl" is men
tioned in the line. The sequences "-*" and "- " are
specifically ignored so that you could, if you were so
inclined, say
#!/bin/sh -- # -*- perl -*- -p
eval 'exec perl -wS $0 ${1+"$@"}'
if $running_under_some_shell;
to let Perl see the -p switch.
A similar trick involves the env program, if you have it.
#!/usr/bin/env perl
The examples above use a relative path to the perl inter
preter, getting whatever version is first in the user's
path. If you want a specific version of Perl, say,
perl5.005_57, you should place that directly in the #!
line's path.
[SNIP]
Martien
--
|
Martien Verbruggen | 42.6% of statistics is made up on the
Trading Post Australia Pty Ltd | spot.
|
------------------------------
Date: Mon, 12 Nov 2001 22:32:29 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Unencoding
Message-Id: <slrn9v0jgl.2q5.mgjv@verbruggen.comdyn.com.au>
On Mon, 12 Nov 2001 08:51:18 GMT,
Bart Lateur <bart.lateur@skynet.be> wrote:
> Geoff wrote:
>
>>> $code =~ s/([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>>Does not work!!
> No. It's more like:
>
> $code =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>
> But if you don't have a good reason to reinvent that wheel, I'd suggest
> using a CGI library to decode those CGI parameters, like CGI, CGI::Lite,
> CGI::Minimal, CGI::Query, and then some more.
Assuming that the OP does indeed need this to decode URLs or query
strings:
iWouldn't the code you give only work on machines where the
character collation is the same as specified for these escape codes?
This will be largely true on machines with ASCII based character sets,
but I doubt it will work correctly on EBCDIC machines, for example.
Has anyone tried this approach on EBCDIC machines? Or the reverse with
sprintf "%%%02x", ord $char
?
Martien
--
|
Martien Verbruggen | We are born naked, wet and hungry.
Trading Post Australia Pty Ltd | Then things get worse.
|
------------------------------
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 2118
***************************************