[23716] in Perl-Users-Digest
Perl-Users Digest, Issue: 5922 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 10 18:12:25 2003
Date: Wed, 10 Dec 2003 15:10:21 -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 Wed, 10 Dec 2003 Volume: 10 Number: 5922
Today's topics:
Re: escape sequence for tab not working (Tad McClellan)
Re: How to run _init for all ancestor classes in diamon (Amir Karger)
Re: How to run _init for all ancestor classes in diamon <ubl@schaffhausen.de>
Re: How to run _init for all ancestor classes in diamon <tassilo.parseval@rwth-aachen.de>
Re: HOWTO remove empty lines with Regex (Anno Siegel)
Re: HOWTO remove empty lines with Regex (Tad McClellan)
Re: HOWTO remove empty lines with Regex <xx087@freenet.carleton.ca>
Re: HOWTO remove empty lines with Regex <pinyaj@rpi.edu>
Re: Idiom for array index that I'm foreach'ing over? <bik.mido@tiscalinet.it>
Re: Memory: measuring 5 limitations <jwillmore@remove.adelphia.net>
Re: MIME::Lite / Net::SMTP question <jwillmore@remove.adelphia.net>
Multi-Line Regex <mikeflan@earthlink.net>
Re: Multi-Line Regex (Anno Siegel)
Re: Multi-Line Regex <noreply@gunnar.cc>
Re: Multi-Line Regex <asu1@c-o-r-n-e-l-l.edu>
Re: Multi-Line Regex (Tad McClellan)
Re: Multi-Line Regex <uri@stemsystems.com>
Re: Multi-Line Regex <asu1@c-o-r-n-e-l-l.edu>
Re: Multi-Line Regex <mikeflan@earthlink.net>
Re: Multi-Line Regex <mikeflan@earthlink.net>
perlcc <linh@chello.no>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 10 Dec 2003 08:08:17 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: escape sequence for tab not working
Message-Id: <slrnbtea6h.u5c.tadmc@magna.augustmail.com>
naniwadekar <nani3skip45@hotmail.com> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote -
>>
>> Do not re-type Perl code
> But since the
> followup tackled the typo AND (not INsteaDOf) my
> question, I need have no regrets.
Thank you for making your selfishness so explicit,
I now know what I need to do.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 Dec 2003 07:14:17 -0800
From: amirkargerweb@yahoo.com (Amir Karger)
Subject: Re: How to run _init for all ancestor classes in diamond inheritance
Message-Id: <87671b7a.0312100714.26de61d6@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<br5gvv$pai$1@nets3.rz.RWTH-Aachen.DE>...
> Also sprach Amir Karger:
>
> > So how do I write Vehicle::_init such that SolarCar::_init will
> > inherit it and call Vehicle::_init, SolarVehicle::_init, and
> > WheeledVehicle::_init? (Writing SolarCar::_init so that it overloads
> > Vehicle::_init and calls the parent class _init's separate would be
> > unelegant, it seems to me.)
>
> I don't agree here. Vehicle is the most generic of all your classes and
> its _init Method should really only arrange for those things that every
> vehicle has. Furthermore, Vehicle shouldn't have to bother whether it is
> used as a superclass or not. Ideally, it doesn't even realize it.
This is obviously an OO theory question, and I am very weak on OO
theory.
How does the idea that a class should be easily inheritable interface
with the idea that a class shouldn't know it's being inherited from?
Are classes really not supposed to know they're inherited from? What
about abstract classes, which can't even instantiate objects?
Obviously they'll be inherited from!
I guess the point of your argument is that all code in the base class
should represent the base class' functionality, and a class shouldn't
just be a convenient dumping ground for functionality that happens to
be shared between all the subclasses of that class. To me, though,
this conflicts with the idea that I can write the code just once in
the base class, rather than writing a new _init in every subclass.
That makes it easier to inherit, avoids bugs in needlessly replicated
_init functions, and elegance-wise avoids redundant code. So the real
question is, is that True or False Laziness? I can see an argument
for each side. As it happens, in my application, I don't think
there'll ever be more than four classes. But what if I had thirty
classes; should I really put a new _init in each one?
Would you be happier if I did this:
package Vehicle;
# Just do stuff that applies to Vehicle AND its subclasses
sub _init {
shift->{"name"} = "default name";
}
package ClassThatInheritsFromVehicle;
@ISA = qw(Vehicle);
# Do stuff that applies only to subclasses
sub _init {
# put my Vehicle::_init here
}
and then have every subclass inherit from there instead? Now I'm
creating a class whose whole point is to foster good inheritance, so
it makes sense to put an inheritance-helping _init in there. Vehicle
now has only Vehicle-related functionality, and all the sub-Vehicle
classes just inherit from Vehicle. But is it really worth creating a
class like this just to allow inheritance? My sense of OO is that it's
OK if I centralize code for all the subclasses in a superclass, as
long as that code doesn't break the superclass. This may break OO
theory, but is it the kind of breaking that Perl approves of and
sometimes encourages?
I guess this problem is arising because I'm trying to force a non-Perl
OO model (essentially calling every ancestor class' new()) onto Perl.
Still, I would think it's the rule rather than the exception that
you'd want objects of the child classes to have the attributes of the
parent classes. (Perl 6 has Rules AND Exceptions :) And there are
probably many cases out there where there's more than one layer of
inheritance, and some multiple inheritance, such that you can't just
call $self->SUPER::init(). What have other folks used in this
situation?
> > I feel like my problem here isn't that Perl
> > can't do it, but just a syntax problem. I really just want a "foreach
> > (@ISA)" - but how do I write an inheritable Vehicle::_init and refer
> > to @ISA such that the @ISA of the package in which _init is currently
> > running is used, instead of always @Vehicle::ISA or @{ref($self) .
> > "::ISA"}.
As it happens, I realized I can solve this problem by passing $class
as the first argument to _init as I move up the ladder. Then I just
use
@{$class . "::ISA"}. Of course, this is pretty ugly. It's kind of
strange to me to think that if you call $foo->class::bar() then bar()
can't tell what class it was called with. caller() doesn't seem to
give me the right info either. So I'm still somewhat unsatisfied.
(Sounds like the kind of thing Perl6 would have an operator for,
though. How about <- to mean the class I was called with?)
But the rest of your email is probably the more important part.
[Generously offered code snipped]
> The only problem with this is that Vehicle's _init method is now called
> twice because both WheelVehicle::_init and SolarVehicle::_init will call
> it.
This is a very minor problem which also existed in my code: I can put
a hash in the object that stores which classes' inits have been called
on the object so far, and return if $self->{"_init"}{$class}.
-Amir
------------------------------
Date: Wed, 10 Dec 2003 16:35:03 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: How to run _init for all ancestor classes in diamond inheritance
Message-Id: <br7hhe$5v9$1@news.dtag.de>
Amir Karger wrote:
> I've got a simple diamond class hierarchy (code below). In order to
> bore people, I've chosen to use Vehicle as the base class.
> SolarVehicle and WheeledVehicle inherit from Vehicle, and SolarCar
> inherits from both of those child classes. (But you could have a
> SolarSeaPlane that's a SolarVehicle and not a WheeledVehicle.)
Everytime you have a SolarWheeledMountableWindowedScollableCyberVehicle
there is a simple answer:
USE DELEGATION
or more specific the decorator pattern.
bye
malte
------------------------------
Date: 10 Dec 2003 15:59:52 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: How to run _init for all ancestor classes in diamond inheritance
Message-Id: <br7fto$j55$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Amir Karger:
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<br5gvv$pai$1@nets3.rz.RWTH-Aachen.DE>...
>> Also sprach Amir Karger:
>>
>> > So how do I write Vehicle::_init such that SolarCar::_init will
>> > inherit it and call Vehicle::_init, SolarVehicle::_init, and
>> > WheeledVehicle::_init? (Writing SolarCar::_init so that it overloads
>> > Vehicle::_init and calls the parent class _init's separate would be
>> > unelegant, it seems to me.)
>>
>> I don't agree here. Vehicle is the most generic of all your classes and
>> its _init Method should really only arrange for those things that every
>> vehicle has. Furthermore, Vehicle shouldn't have to bother whether it is
>> used as a superclass or not. Ideally, it doesn't even realize it.
>
> This is obviously an OO theory question, and I am very weak on OO
> theory.
> How does the idea that a class should be easily inheritable interface
> with the idea that a class shouldn't know it's being inherited from?
> Are classes really not supposed to know they're inherited from? What
> about abstract classes, which can't even instantiate objects?
> Obviously they'll be inherited from!
The problem is when superclasses contain code that is really just there
to satisfy the needs of a particular subclass. This makes deriving
another class harder since this new class might not have these
requirements.
> I guess the point of your argument is that all code in the base class
> should represent the base class' functionality, and a class shouldn't
> just be a convenient dumping ground for functionality that happens to
> be shared between all the subclasses of that class. To me, though,
> this conflicts with the idea that I can write the code just once in
> the base class, rather than writing a new _init in every subclass.
Common code should go into superclasses, that's right. What I didn't
like with your approach was that the class Vehicle would look down onto
its child classes and see from which classes those are derived by
looking at their @ISA. Consider you derive a new class from SolarVehicle
that - for some reason - only wants to call Vehicle's _init method and
not that of SolarVehicle. This would be impossible in an approach where
the class highest in the hierarchy decides which init-methods to call.
> That makes it easier to inherit, avoids bugs in needlessly replicated
> _init functions, and elegance-wise avoids redundant code. So the real
> question is, is that True or False Laziness? I can see an argument
> for each side. As it happens, in my application, I don't think
> there'll ever be more than four classes. But what if I had thirty
> classes; should I really put a new _init in each one?
>
> Would you be happier if I did this:
>
> package Vehicle;
> # Just do stuff that applies to Vehicle AND its subclasses
> sub _init {
> shift->{"name"} = "default name";
> }
>
> package ClassThatInheritsFromVehicle;
> @ISA = qw(Vehicle);
> # Do stuff that applies only to subclasses
> sub _init {
> # put my Vehicle::_init here
> }
>
> and then have every subclass inherit from there instead? Now I'm
> creating a class whose whole point is to foster good inheritance, so
> it makes sense to put an inheritance-helping _init in there. Vehicle
> now has only Vehicle-related functionality, and all the sub-Vehicle
> classes just inherit from Vehicle. But is it really worth creating a
> class like this just to allow inheritance? My sense of OO is that it's
> OK if I centralize code for all the subclasses in a superclass, as
> long as that code doesn't break the superclass. This may break OO
> theory, but is it the kind of breaking that Perl approves of and
> sometimes encourages?
It's probably best to put OO theory aside when programming Perl. The
fact that you can look at your child classes' @ISA is already something
that most other object-oriented classes don't allow and would consider a
severe violation against the principles of OO. Screw that, the purity of
ideas is never something Perl cared about a lot.
> As it happens, I realized I can solve this problem by passing $class
> as the first argument to _init as I move up the ladder. Then I just
> use
> @{$class . "::ISA"}. Of course, this is pretty ugly. It's kind of
> strange to me to think that if you call $foo->class::bar() then bar()
> can't tell what class it was called with. caller() doesn't seem to
> give me the right info either. So I'm still somewhat unsatisfied.
> (Sounds like the kind of thing Perl6 would have an operator for,
> though. How about <- to mean the class I was called with?)
Are you sure that caller() wont help you? The first item of the list
returned by caller() is always the package from which the current
function was called. That should be enough.
>> The only problem with this is that Vehicle's _init method is now called
>> twice because both WheelVehicle::_init and SolarVehicle::_init will call
>> it.
>
> This is a very minor problem which also existed in my code: I can put
> a hash in the object that stores which classes' inits have been called
> on the object so far, and return if $self->{"_init"}{$class}.
Sounds too complicated. Just make sure that the _init() classes only do
things that wont break when they are done twice.
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: 10 Dec 2003 14:07:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: HOWTO remove empty lines with Regex
Message-Id: <br79aj$mej$2@mamenchi.zrz.TU-Berlin.DE>
tor <torfinnk@hotmail.com> wrote in comp.lang.perl.misc:
> Hi
> I wan't to remove all empty lines in a file.
> How can I do that with a regex:
> s/<something>//;
> What is this <something>
Apparently you want to remove empty lines not from a file, but a string.
There may be such a <something>, but it's easier with a different regex.
s/\n+/\n/g
does it.
tr/\n//s
does it faster.
Anno
------------------------------
Date: Wed, 10 Dec 2003 08:25:19 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: HOWTO remove empty lines with Regex
Message-Id: <slrnbteb6f.u6n.tadmc@magna.augustmail.com>
tor <torfinnk@hotmail.com> wrote:
> I wan't to remove all empty lines in a file.
perl -n -i.old -e 'print unless /^\s+$/' file
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 Dec 2003 14:58:53 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: HOWTO remove empty lines with Regex
Message-Id: <slrnbted6v.srm.xx087@smeagol.ncf.ca>
Tad McClellan <tadmc@augustmail.com> wrote:
> tor <torfinnk@hotmail.com> wrote:
> > I wan't to remove all empty lines in a file.
>
> perl -n -i.old -e 'print unless /^\s+$/' file
Nitpick mode: remove empty lines too:
perl -n -i.old -e 'print unless /^\s*$/' file
^
^
--
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca
------------------------------
Date: Wed, 10 Dec 2003 10:24:31 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: HOWTO remove empty lines with Regex
Message-Id: <Pine.SGI.3.96.1031210102354.42499A-100000@vcmr-64.server.rpi.edu>
On 10 Dec 2003, Glenn Jackman wrote:
>Tad McClellan <tadmc@augustmail.com> wrote:
>> tor <torfinnk@hotmail.com> wrote:
>> > I wan't to remove all empty lines in a file.
>>
>> perl -n -i.old -e 'print unless /^\s+$/' file
>
>Nitpick mode: remove empty lines too:
> perl -n -i.old -e 'print unless /^\s*$/' file
But \n is matched by \s, and the $ anchor doesn't HAVE to match a newline,
so on a string like "\n", both /^\s+$/ and /^\s*$/ match.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 10 Dec 2003 22:52:04 GMT
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <nj9stvor4l728tbtcd1gcuur8n9de2a4bc@4ax.com>
On 09 Dec 2003 21:52:10 GMT, Abigail <abigail@abigail.nl> wrote:
>{} >Unlike Perl6, which just throws out 50 years of programming language
>{} >design out of the window, passes Python on the wrong side and makes
>{} >whitespace significant in new painful and revolting ways.
>{}
>{} Just out of curiosity: is this definitive or are there chances that
>{} such "features" may be removed/changed before before Perl6 is actually
>{} released in productive form?
>
>Nothing is definitive, but Larry and Damian seem to be convinced that
>the gain of saving 2 characters on an if() are worth sacrificing the
>non-significance of whitespace, that I say the chances are small.
It would be nice if this behaviour could be triggered somehow, say by
means of yet another cmd line switch or a pragma...
But shouldn't Perl6 be the "community rewrite" (IIRC) of Perl? What
does the community think here?!?
On Wed, 10 Dec 2003 06:19:10 -0600, "Eric J. Roode"
<REMOVEsdnCAPS@comcast.net> wrote:
>Alas, very slim. :-( I have this nagging feeling that version 6 is
>going to be the worst thing that ever happened to Perl.
Well I know next to nothing about Perl6, but as a general disposition
I feel inclined to anticipate with enthusiasm any kind of innovation,
not to fear it.
Now, what I came to know in this thread is certainly something that I
completely dislike, agreeing with you both (FWIW MHO!). But I'll wait
to see the living creature...
BTW: what would be the best resource for discussing own
ideas/questions about feaures of (any future major release of Perl,
but then most definitely) Perl6? Please not that I'm talking about
(possibly) naive or generic issues, so too technical a
forum/board/whatever may not be well suited for them...
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: Wed, 10 Dec 2003 20:28:15 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Memory: measuring 5 limitations
Message-Id: <20031210152815.20571468.jwillmore@remove.adelphia.net>
On 10 Dec 2003 01:24:14 -0800
bart@nijlen.com (Bart Van der Donck) wrote:
> So, 1 basic question: is there a command like:
> `` memory myscript.pl =B4=B4
> that would display the memory of my script?
>=20
> I don't want to code an entire program and then find out that I
> can't use it because of memory restrictions.
*If* you have shell access, you *may* be able to use=20
'time "name of script here"'.
This will give you information about the execution of the script. Not
Perl, but it will give you more information than what you're getting
now.
If you wanted to do it in Perl, best start with a simple=20
'perl -V'=20
at the command line to see what your host has. Some of the neat
debugging stuff you may not be able to do with you host's build of
Perl. In fact, if theu use a canned distro of Linux, *most* distros
don't build Perl with debugging enabled. Why? I don't know.
As a last resort, look for another host :-)
Just my $0.02
--=20
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt=20
for more information.
a fortune quote ...
Gnagloot, n.: A person who leaves all his ski passes on his
<jacket just to impress people. -- Rich Hall, "Sniglets"=20
------------------------------
Date: Wed, 10 Dec 2003 19:54:46 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: MIME::Lite / Net::SMTP question
Message-Id: <20031210145446.114da3cf.jwillmore@remove.adelphia.net>
On 10 Dec 2003 04:11:53 -0800
gsanuser <gsanuser_member@newsguy.com> wrote:
> We are using MIME::Lite (ver 2.117) and Net::SMTP (ver 2.19) for
> sending mail from a Solaris box (perl 5.6.1).
> We have a method which simplified looks like:
> sub sendMail (
> my $msg = build MIME::Lite(...) ;
> attach $msg (...attachement ....) ;
> $msg->send_by_smtp() || return 0;
> return 1;
> )
> we are finally checking if sendMail() returns 0 or 1 in order to
> flag mails correctly sent or not.
>
> It appears that this way we are able to trap errors like "cannot
> connect to host", or some STMP errors (like 500 Syntax error) but
> not all, i.e. error 452(insufficient system storage) is not detected
> (that is, our sendMail() returns 1 as it were no problems).
>
> Particularly errors from dataend() are not trapped. Following code
> from MIME::Lite ver 2.117):
>
> my $smtp = MIME::Lite::SMTP->new(@args) or Carp::croak("Failed to
> connect to mail server: $!\n");
> $smtp->mail($from) or Carp::croak("SMTP MAIL command failed:
> $!\n".$smtp->message."\n");
> $smtp->to(@to_all) or Carp::croak("SMTP RCPT command failed:
> $!\n".$smtp->message."\n");
> $smtp->data() or Carp::croak("SMTP DATA command failed:
> $!\n".$smtp->message."\n");
> $self->print_for_smtp($smtp);
> $smtp->dataend() ;
>
> Just asking group if this is a bug or a feature, and what is the
> best way to correct this issue.
>
> Just adding something like:
>
> $smtp->dataend() or Carp::croak("SMTP DATAEND command failed:
> $!\n".$smtp->message."\n");
>
> or
>
> unless (($smtp->code())== 250){Carp::croak("Mail is Not Correltly
> Delivered via SMTP");}
I'm not 100% sure if this will work, but thinking back to a script I
wrote some time back, I seem to remember using this. I just wraped
the whole process of sending the email in an eval block. Sometimes
the errors encounter by the various email modules will not result in
the script dying, but the method used returning undef or the message
from the server.
So, you might try something like (untested):
eval{
my $smtp = MIME::Lite::SMTP->new(@args);
$smtp->mail($from);
$smtp->to(@to_all);
$smtp->data():
$self->print_for_smtp($smtp);
$smtp->dataend() ;
};
die "$@\n" if($@);
Again, I'm not 100% sure. Forgive my sin of not checking the
documentation first before posting.
Net::SMTP also has a 'Debug' setting, so you could fashion something
around that as well. At the very least, find out what the behavior of
the whole process is. I think MIME::Lite has a similar facility.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Sex is a natural bodily process, like a stroke.
------------------------------
Date: Wed, 10 Dec 2003 14:38:59 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Multi-Line Regex
Message-Id: <3FD730C6.FB7F6C0@earthlink.net>
I've got a simple question. I want to
expand a single regex to show it on multiple lines.
At first I had:
last if (($line =~ m/^Subject:/i) and
($line =~ m/gifts online|ephedra|long distance for
|cheapest on the inter|Analyst's Pick|stretch mark
|failure announc|failure advice|failure notice
|pharmacy|lose inch|healthcare costs|security pa
|net service|network update|abort letter
|you forgot to write|ploma|security up
|network upgrade|Failure Letter|failure message
|credit /ig));
So I thought all the spaces on the front of
the lines were screwing it up. So I
changed it to:
last if (($line =~ m/^Subject:/i) and
($line =~ m/gifts online|ephedra|long distance for
|cheapest on the inter|Analyst's Pick|stretch mark
|failure announc|failure advice|failure notice
|pharmacy|lose inch|healthcare costs|security pa
|net service|network update|abort letter
|you forgot to write|ploma|security up
|network upgrade|Failure Letter|failure message
|credit /ig));
Oddly, even this last one does not work,
meaning is doesn't see 'credit' or 'abort letter' etc)
even though there are no spaces on the
end of the lines, that you can't see.
If I put it all on one line it works. Do
I really have to do that? Surely not.
Can anybody tell me how to do this?
I tried several ways to answer this question
myself, but none gave me the answer.
Mike Flannigan
------------------------------
Date: 10 Dec 2003 14:43:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Multi-Line Regex
Message-Id: <br7ben$mej$4@mamenchi.zrz.TU-Berlin.DE>
Mike Flannigan <mikeflan@earthlink.net> wrote in comp.lang.perl.misc:
>
> I've got a simple question. I want to
> expand a single regex to show it on multiple lines.
You want the /x modifier on the regex.
[snip]
Anno
------------------------------
Date: Wed, 10 Dec 2003 16:00:20 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Multi-Line Regex
Message-Id: <br7chq$5bhe$1@ID-184292.news.uni-berlin.de>
Mike Flannigan wrote:
> I want to expand a single regex to show it on multiple lines.
<snip>
> last if (($line =~ m/^Subject:/i) and
> ($line =~ m/gifts online|ephedra|long distance for
> |cheapest on the inter|Analyst's Pick|stretch mark
> |failure announc|failure advice|failure notice
> |pharmacy|lose inch|healthcare costs|security pa
> |net service|network update|abort letter
> |you forgot to write|ploma|security up
> |network upgrade|Failure Letter|failure message
> |credit /ig));
>
> Oddly, even this last one does not work, meaning is doesn't see
> 'credit' or 'abort letter' etc)
"credit " is not included in the string "credit", and "abort letter\n"
is not included in "abort letter".
> If I put it all on one line it works. Do I really have to do that?
> Surely not.
> Can anybody tell me how to do this?
You may want to add the /x modifier and escape the space characters.
The /g modifier is redundant.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 10 Dec 2003 15:15:37 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Multi-Line Regex
Message-Id: <Xns944D685FC57B0asu1cornelledu@132.236.56.8>
Mike Flannigan <mikeflan@earthlink.net> wrote in news:3FD730C6.FB7F6C0
@earthlink.net:
>
> I've got a simple question. I want to
> expand a single regex to show it on multiple lines.
> At first I had:
>
> last if (($line =~ m/^Subject:/i) and
> ($line =~ m/gifts online|ephedra|long distance for
> |cheapest on the inter|Analyst's Pick|stretch mark
> |failure announc|failure advice|failure notice
> |pharmacy|lose inch|healthcare costs|security pa
> |net service|network update|abort letter
> |you forgot to write|ploma|security up
> |network upgrade|Failure Letter|failure message
> |credit /ig));
Anno and Gunnar have answered your original question. I just want to point
out that it would probably be more efficient and maintainable to prefer the
following:
my $lc_line = lc($line);
last if (($lc_line =~ /^subject:/)
and ($lc_line =~ /gifts online/
or /ephedra/
or /long distance for/
or /cheapest on the inter/
or /analyst's pick/
or /stretch mark/
or /failure announc/
or /failure advice/
or /failure notice/
or /pharmacy/
or /lose inch/
# more conditions
));
Of course, I do not have any benchmarks to back my hypothesis :)
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 10 Dec 2003 10:45:30 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Multi-Line Regex
Message-Id: <slrnbtejda.uji.tadmc@magna.augustmail.com>
Mike Flannigan <mikeflan@earthlink.net> wrote:
>
> I want to
> expand a single regex to show it on multiple lines.
Others have helped with that, but I think there is a better
solution to your X-Y problem:
my @redflags = (
'gifts online',
'ephedra',
'long distance for',
);
last if $line =~ m/^Subject:/i and
grep $line =~ m/$_/i, @redflags; # or: m/\Q$_/i
Avoiding a huge smushed-together "list" embedded in a regex
seems much nicer to me, and I will usually trade off execution
speed to gain ease of maintenance.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 10 Dec 2003 17:35:34 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Multi-Line Regex
Message-Id: <x7vfooa84b.fsf@mail.sysarch.com>
>>>>> "ASU" == A Sinan Unur <asu1@c-o-r-n-e-l-l.edu> writes:
> my $lc_line = lc($line);
> last if (($lc_line =~ /^subject:/)
> and ($lc_line =~ /gifts online/
> or /ephedra/
> or /long distance for/
and where is $_ being set?
> Of course, I do not have any benchmarks to back my hypothesis :)
or tested code! :)
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: 10 Dec 2003 17:47:43 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Multi-Line Regex
Message-Id: <Xns944D8229819B0asu1cornelledu@132.236.56.8>
Uri Guttman <uri@stemsystems.com> wrote in
news:x7vfooa84b.fsf@mail.sysarch.com:
>>>>>> "ASU" == A Sinan Unur <asu1@c-o-r-n-e-l-l.edu> writes:
>
> > my $lc_line = lc($line);
> > last if (($lc_line =~ /^subject:/)
> > and ($lc_line =~ /gifts online/
> > or /ephedra/
> > or /long distance for/
>
> and where is $_ being set?
>
> > Of course, I do not have any benchmarks to back my hypothesis :)
>
> or tested code! :)
Arrgh, you are right. That teaches me not to edit stuff in my newsreader
again! Thank you for catching that.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Wed, 10 Dec 2003 19:18:47 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Multi-Line Regex
Message-Id: <3FD7725C.41D722BD@earthlink.net>
Anno Siegel wrote:
> Mike Flannigan <mikeflan@earthlink.net> wrote in comp.lang.perl.misc:
> >
> > I've got a simple question. I want to
> > expand a single regex to show it on multiple lines.
>
> You want the /x modifier on the regex.
>
Thanks to all. I can't figure out why it works, but it works.
Everything I have on extended regular expressions says
it has (?something). Not in this case I guess.
I'm trying to figure out why spaces need to be escaped
also.
Mike
------------------------------
Date: Wed, 10 Dec 2003 19:21:58 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Multi-Line Regex
Message-Id: <3FD7731B.45953316@earthlink.net>
Tad McClellan wrote:
> Others have helped with that, but I think there is a better
> solution to your X-Y problem:
>
> my @redflags = (
> 'gifts online',
> 'ephedra',
> 'long distance for',
> );
>
> last if $line =~ m/^Subject:/i and
> grep $line =~ m/$_/i, @redflags; # or: m/\Q$_/i
>
> Avoiding a huge smushed-together "list" embedded in a regex
> seems much nicer to me, and I will usually trade off execution
> speed to gain ease of maintenance.
Thanks. I do like that. I learned grep once, but can never
get comfortable enough with it to use it again. Can't reach
that critical mass I guess.
I have used this and exported all the 'reject' stuff out to
separate text files.
Mike
------------------------------
Date: Wed, 10 Dec 2003 23:38:34 +0100
From: "ngoc" <linh@chello.no>
Subject: perlcc
Message-Id: <7gNBb.5266$Y06.86442@news4.e.nsc.no>
Hi
I try to compile my perl program to binary form using command
perlcc -o program_name program_name.pl
but get error message
No definition for sub Fcntl::FD_CLOEXEC
No definition for sub Fcntl::FD_CLOEXEC (unable to autoload)
No definition for sub Fcntl::O_RANDOM
No definition for sub Fcntl::O_RANDOM(unable to autoload)
...............................................
..............................................
and
Can't locate object method "savecv" via package "B::SPECIAL" (perhaps you
forgot to load "B::SPECIAL"
My PERL5LIB point to Fcntl location, so I don't know what is wrong
Please help me.
Ngoc
------------------------------
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 5922
***************************************