[21722] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3926 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 6 21:06:19 2002

Date: Sun, 6 Oct 2002 18:05:07 -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           Sun, 6 Oct 2002     Volume: 10 Number: 3926

Today's topics:
        ANN: apprentice.perl.org <uri@stemsystems.com>
    Re: Dealing with database problems gracefully? <Juha.Laiho@iki.fi>
    Re: Dealing with database problems gracefully? <rereidy@indra.com>
    Re: Detecting Printers and/or Routers on a netwotk (win (Alan Barclay)
        finding processes <nospam@rostie.net>
    Re: finding processes <s_grazzini@hotmail.com>
    Re: finding processes <s_grazzini@hotmail.com>
    Re: finding processes <krahnj@acm.org>
    Re: Help! How do you move one html page to another in P <flavell@mail.cern.ch>
    Re: How Can I Read a Single Line at a Time from an Open <s_grazzini@hotmail.com>
    Re: How Can I Read a Single Line at a Time from an Open <play.ball@usa.net>
    Re: How to find array element  index efficently <s_grazzini@hotmail.com>
    Re: How to find array element  index efficently <krahnj@acm.org>
    Re: How to find array element  index efficently ctcgag@hotmail.com
    Re: Is this a bug in perl? <s_grazzini@hotmail.com>
    Re: Is this a bug in perl? <flavell@mail.cern.ch>
    Re: Open File problem (kazchan)
    Re: regex o modifier <s_grazzini@hotmail.com>
    Re: regex o modifier <darin@naboo.to.org.no.spam.for.me>
    Re: regex o modifier <roy@panix.com>
    Re: Socket server & client only connect on same machine (Jean Gagnon)
    Re: || versus OR <bobx@linuxmail.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 06 Oct 2002 19:27:55 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: ANN: apprentice.perl.org
Message-Id: <x71y734bb8.fsf@mail.sysarch.com>


a new site in the perl.org fiefdom has arrived. it is called
apprentice.perl.org and it is for those who want to help out with perl
projects and learn from experienced perl hackers. the concept harkens
back to the days of yore when apprentices worked for mentors in exchange
for training. so those of you who have perl project and want to teach
can list them on the site. those of you who want to learn more perl,
work on public projects and be mentored by expert perl hackers, sign up
for projects.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Sun, 06 Oct 2002 19:02:00 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Dealing with database problems gracefully?
Message-Id: <anq189$gd7$1@ichaos.ichaos-int>

"Simon Harvey" <ReplyToGroup@thanks.com> said:
>I'm doing aproject on behald of my students union. We have a database that
>we dont actually control but has kndly been provided by the university
>itself.
>
>The downside of that is that we will never know if it is going offline.
 ...
>Anyway, sorry about the rant. I do actaully have a question. I know a
>little bit about eval and was wondering if I should put my database
>related calls (such as making the initial connection and executing
>statements etc) within eval blocks?
>
>Someone told me that this was a bad idea before but then how else do
>i make the application robust? Its not that big a program but because
>it is actually being deployed in a real world enviroment it absolutely
>must have error control.
>
>Another guy told me that evel was exctly what I should use so now I'm
>all confused!

Check statement by statement which ones use die() as the "internal"
error control mechanism for the statement. Use eval on those - because
that's the only way you can prevent the termination of your program
at those statements. For those statements that don't use die(), just
check the return values rigorously -- and try to find out how to recover
from problem situations (f.ex. if a database is shut down and restarted,
you'll need to have your code to reconnect to the database).
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


------------------------------

Date: Sun, 06 Oct 2002 17:17:08 -0600
From: Ron Reidy <rereidy@indra.com>
Subject: Re: Dealing with database problems gracefully?
Message-Id: <3DA0C474.752CA96F@indra.com>

Simon Harvey wrote:
> 
> Hi all,
> 
> I'm doing aproject on behald of my students union. We have a database that
> we dont actually control but has kndly been provided by the university
> itself.
> 
> The downside of that is that we will never know if it is going offline. This
> led me onto the question of dealing with errors more genrally in perl, on
> which there seems to be very little external comment or documentation. The
> official docs are there and are very good (as always) for people who are
> good at perl already (not really me), but what would help would be a
> discussion of the features and perhaps a faq and tutorial. Something that
> newbies can get into. I sent this request to the perl faqs suggestions page
> but it doesnt seem that responsive as I know a few people also sent ina
> similar request.
> 
> Anyway, sorry about the rant. I do actaully have a question. I know a little
> bit about eval and was wondering if I should put my database related calls
> (such as making the initial connection and executing statements etc) within
> eval blocks?
> 
> Someone told me that this was a bad idea before but then how else do i make
> the application robust? Its not that big a program but because it is
> actually being deployed in a real world enviroment it absolutely must have
> error control.
> 
> Another guy told me that evel was exctly what I should use so now I'm all
> confused!
> 
> Does anyone have any thoughts or advise about anything above? Does anyone
> have the idea of the perl faq guys?
> 
> I really think there should be an "Error Handling in Perl" faq (or pehaps
> just a section within a faq). Anything would be better than nothing
> 
> Kind thanks to all who share their thoughts (and maybe even help me!! :))
> 
> Take Care
> Simon
Use eval {} blocks.
-- 
Ron Reidy
Oracle DBA


------------------------------

Date: 6 Oct 2002 20:56:12 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Detecting Printers and/or Routers on a netwotk (win32)
Message-Id: <1033937885.57737@elaine.furryape.com>

In article <1lnnpu83pi4jrv2sbkr659f7pilmm408bh@4ax.com>,
Anders Hertz  <a_hertz.ReMoVe@yahoo.com> wrote:
>I'll like to narrow down the unknown part to tell if it's an printer
>or a Network unit (not necesseraly the type, just it's a networking
>unit).

Whatever you do, it will be the same regardless of the language
you use.

I suggest you ask on a group which deals with the devices you're
trying to detect.


------------------------------

Date: Sun, 06 Oct 2002 15:05:52 -0500
From: Randy <nospam@rostie.net>
Subject: finding processes
Message-Id: <de41qusfsk8ql0hb0nhhtdq33hkciqsmcq@4ax.com>

I am trying to write a perl script that will list all the PIDs of
sendmail processes, and then print the working directory of each
process. The shell command that prints out the PIDs of the sendmail
processes is:

ps -ef | awk '/sendmail/{print $2}'

Here is what I tried:

#!/usr/local/perl
foreach $s_pid (`ps -ef \| awk '\/sendmail\/{print \$2}'`) {
        system("`cd \/proc\/$s_pid\/cwd; \/bin\/pwd`");
}


But it doesn't work.
Is there some way to get around quoting special characters like / so I
could just use a system command like
ps -ef | awk '/sendmail/{print $2}'
inside of the perl script?




------------------------------

Date: Sun, 06 Oct 2002 20:28:36 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: finding processes
Message-Id: <U11o9.40186$YI.8904164@twister.nyc.rr.com>

Randy <nospam@rostie.net> wrote:
> I am trying to write a perl script that will list all the PIDs of
> sendmail processes, and then print the working directory of each
> process. The shell command that prints out the PIDs of the sendmail
> processes is:
> 
> ps -ef | awk '/sendmail/{print $2}'
> 
> Here is what I tried:
> 
> #!/usr/local/perl
> foreach $s_pid (`ps -ef \| awk '\/sendmail\/{print \$2}'`) {
>         system("`cd \/proc\/$s_pid\/cwd; \/bin\/pwd`");
> }
> 
> 
> But it doesn't work.
> Is there some way to get around quoting special characters like / 

The slash isn't special unless if it's being used as the quote-
character for m// or whatever.

> so I could just use a system command like
> ps -ef | awk '/sendmail/{print $2}'
> inside of the perl script?

Check:

  $ perldoc -q 'output of a command'
  Found in /usr/local/lib/perl5/5.8.0/pod/perlfaq8.pod
       Why can't I get the output of a command with system()?

And please don't call awk from perl; it embarrasses both
of them. :)

  #!/usr/bin/perl -l

  foreach (`ps -ef`) {
    next unless /sendmail/;
    my (undef,$pid) = split;

    # that /proc stuff isn't portable, but:
    print "$pid: ", readlink "/proc/$pid/cwd"; 
  }

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


------------------------------

Date: Sun, 06 Oct 2002 20:44:36 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: finding processes
Message-Id: <Ug1o9.40202$YI.8910597@twister.nyc.rr.com>

Steve Grazzini <s_grazzini@hotmail.com> wrote:
> Randy <nospam@rostie.net> wrote:
>> 
>> #!/usr/local/perl
>> foreach $s_pid (`ps -ef \| awk '\/sendmail\/{print \$2}'`) {
>>         system("`cd \/proc\/$s_pid\/cwd; \/bin\/pwd`");
>> }
 ...

> Check:
> 
>   $ perldoc -q 'output of a command'
>   Found in /usr/local/lib/perl5/5.8.0/pod/perlfaq8.pod
>        Why can't I get the output of a command with system()?

Ah..  I didn't see you had shell backticks in the system()
command-line.

The real problems are:
  1) newline on $s_pid
  2) awk will print its own pid

But still, you shouldn't write shell scripts in Perl.

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


------------------------------

Date: Sun, 06 Oct 2002 23:04:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: finding processes
Message-Id: <3DA0C185.668AB720@acm.org>

Randy wrote:
> 
> I am trying to write a perl script that will list all the PIDs of
> sendmail processes, and then print the working directory of each
> process. The shell command that prints out the PIDs of the sendmail
> processes is:
> 
> ps -ef | awk '/sendmail/{print $2}'
> 
> Here is what I tried:
> 
> #!/usr/local/perl
> foreach $s_pid (`ps -ef \| awk '\/sendmail\/{print \$2}'`) {
>         system("`cd \/proc\/$s_pid\/cwd; \/bin\/pwd`");
> }


#!/usr/local/perl -w
use strict;

for my $s_pid ( map /(\d+)/, `ps -C sendmail -o pid` ) {
    my $link = readlink "/proc/$s_pid/cwd"
        or die "Cannot readlink /proc/$s_pid/cwd: $!";
    print "$link\n";
}

__END__



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Sun, 6 Oct 2002 21:13:52 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Help! How do you move one html page to another in Perl?
Message-Id: <Pine.LNX.4.40.0210062106140.28961-100000@lxplus076.cern.ch>

On Oct 6, Zordiac inscribed on the eternal scroll:

> After a user has input some data I want my Perl script
> to then display another html page.

Smells like an FAQ:

< http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html
#How-do-I-redirect-to-another-page- >

> But what is the best way of moving to another html page?

One of the two kinds of CGI Location: response.  Which to choose,
depends on the context; for many purposes you could choose either.

> I thought I would do this in my Perl script but it is not
> obvious how. Use POST and read variables passed back to the
> script ie have some sort of conditional script start?

Your question seems too vague to offer a more precise answer.

> There must be a standard way of doing this

Looking at FAQs is "a standard way".  At least you'd then have had
something on which to base a substantive question.  (Also, I'd
recommend having a read of the group's posting guidelines, which are
posted here regularly.  Questions which are primarily about the CGI
rather than about the Perl language are considered to be more
appropriately raised on comp.infosystems.www.authoring.cgi )


-- 
               "Go not to Usenet for advice, for they will say both 'No' and
                  'Yes' and 'Try Another Newsgroup' "   - Tim Illingworth



------------------------------

Date: Sun, 06 Oct 2002 18:18:53 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: How Can I Read a Single Line at a Time from an Open File?
Message-Id: <h8%n9.40073$YI.8863062@twister.nyc.rr.com>

Jim <play.ball@usa.net> wrote:
[ swapped the order of the two 'questions' ]

> I am looking for something like a read statement except it will 
> read the entire line.

  $ perldoc -f readline

And the usual way to get readline() is with the 
angle-bracket operator:

  until ($flag) {
    my $line = <FH>;
    ...
  }

Or, most often:

  while (<FH>) {
    # current line is in $_
    ...
  }

> Any help would be appreciated,

And back to your first question:

> This may be simple but I am struggling. I am parsing through a file
> and once I match a single pattern. I want to process the following 
> lines individually until I reach another pattern.

The range operator might be useful here.

  while (<FH>) {
    next unless /$start_pattern/ .. /$end_pattern/;
    ...
  }

Check 'perlop' or the faq:

  $ perldoc -q 'lines between'
  Found in /usr/local/lib/perl5/5.8.0/pod/perlfaq6.pod
       How can I pull out lines between two patterns that are
       themselves on different lines?

HTH
-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


------------------------------

Date: Sun, 6 Oct 2002 14:19:08 -0500
From: "Jim" <play.ball@usa.net>
Subject: Re: How Can I Read a Single Line at a Time from an Open File?
Message-Id: <8a6dnRFmUd2HEzygXTWcpw@News.GigaNews.Com>

Thanks for the quick response Steve,
I did figure out the angle operator in the end. I guess it was simple;
perhaps to simple that is why I stuggled. However, you did shed some
additional light on the subject that I can look into further. I like the
unless approach.

Thanks again,

Jim

"Steve Grazzini" <s_grazzini@hotmail.com> wrote in message
news:h8%n9.40073$YI.8863062@twister.nyc.rr.com...
> Jim <play.ball@usa.net> wrote:
> [ swapped the order of the two 'questions' ]
>
> > I am looking for something like a read statement except it will
> > read the entire line.
>
>   $ perldoc -f readline
>
> And the usual way to get readline() is with the
> angle-bracket operator:
>
>   until ($flag) {
>     my $line = <FH>;
>     ...
>   }
>
> Or, most often:
>
>   while (<FH>) {
>     # current line is in $_
>     ...
>   }
>
> > Any help would be appreciated,
>
> And back to your first question:
>
> > This may be simple but I am struggling. I am parsing through a file
> > and once I match a single pattern. I want to process the following
> > lines individually until I reach another pattern.
>
> The range operator might be useful here.
>
>   while (<FH>) {
>     next unless /$start_pattern/ .. /$end_pattern/;
>     ...
>   }
>
> Check 'perlop' or the faq:
>
>   $ perldoc -q 'lines between'
>   Found in /usr/local/lib/perl5/5.8.0/pod/perlfaq6.pod
>        How can I pull out lines between two patterns that are
>        themselves on different lines?
>
> HTH
> --
> Steve
>
> perldoc -qa.j | perl -lpe '($_)=m("(.*)")'




------------------------------

Date: Sun, 06 Oct 2002 18:25:38 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: How to find array element  index efficently
Message-Id: <Ce%n9.40135$YI.8865375@twister.nyc.rr.com>

Darek Adamkiewicz <d.adamkiewicz@i7.com.pl> wrote:
> Hello folks
> The following subroutine works for me but it's terribly slow
> - but it has some flexibility I'd like to retain:
> sub k2i {
> 	my ($keys, $args) = @_;
> 	my %conv = ();
> 	@conv{ @$keys } = (0..$#{$keys});
> 	return wantarray ? @conv{@$args} : $conv{$args->[0]};	
> }
> 

That's fine, actually.

But if you'd rather have an 'ordered' hash than roll
your own hash-of-indexes, check CPAN:

  Tie::IxHash
  Tie::LLHash
  Tie::SortHash
  Tie::InsertOrderHash
 
-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


------------------------------

Date: Sun, 06 Oct 2002 20:05:16 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to find array element  index efficently
Message-Id: <3DA09770.792FC0A6@acm.org>

Steve Grazzini wrote:
> 
> Darek Adamkiewicz <d.adamkiewicz@i7.com.pl> wrote:
> >
> > The following subroutine works for me but it's terribly slow
> > - but it has some flexibility I'd like to retain:
> > sub k2i {
> >       my ($keys, $args) = @_;
> >       my %conv = ();
> >       @conv{ @$keys } = (0..$#{$keys});
> >       return wantarray ? @conv{@$args} : $conv{$args->[0]};
> > }
> 
> That's fine, actually.
> 
> But if you'd rather have an 'ordered' hash than roll
> your own hash-of-indexes, check CPAN:
> 
>   Tie::IxHash
>   Tie::LLHash
>   Tie::SortHash
>   Tie::InsertOrderHash

Or use a pseudo-hash.  :-)

perldoc perlref



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: 06 Oct 2002 21:30:27 GMT
From: ctcgag@hotmail.com
Subject: Re: How to find array element  index efficently
Message-Id: <20021006173027.839$Cm@newsreader.com>

Darek Adamkiewicz <d.adamkiewicz@i7.com.pl> wrote:
> Hello folks
> The following subroutine works for me but it's terribly slow
> - but it has some flexibility I'd like to retain:

Which flexibility is that?  Life's a series of trade-offs, what are
you willing to trade?

> sub k2i {
>         my ($keys, $args) = @_;
>         my %conv = ();
>         @conv{ @$keys } = (0..$#{$keys});
>         return wantarray ? @conv{@$args} : $conv{$args->[0]};
> }

Your options for making this faster without delving more into how it
is used are pretty slim.  How many times is k2i called?  What is the
pattern at which calls to k2i are interspersed with operations that modify
@$keys?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
                    Usenet Newsgroup Service


------------------------------

Date: Sun, 06 Oct 2002 20:06:09 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Is this a bug in perl?
Message-Id: <RI0o9.40184$YI.8894790@twister.nyc.rr.com>

Walter Roberson <roberson@ibd.nrc.ca> wrote:
> In article <84964d56.0210060855.5ea7509@posting.google.com>,
> Michael McLagan <mmclagan@invweb.net> wrote:
> :   I got a very unexpected result using 5.6.1 on a RH Linux system. 
> :Specifically, I tried:
> 
> :   0xFFFFFFFF >> 32
> 
> :Intuitively, I should have gotten 0.  What I got was 0xFFFFFFFF (-1)!
> 
> 0xFFFFFFFF is a signed number. Shifting a signed number moves a '1'
> bit in at the top. If want 0's to be shifted in instead, you will
> have to force the number to be unsigned.

No...

Assuming the OP is on x86:

Perl takes 0xFFFFFFFF to mean 2**32-1 and not -1, so
it uses an unsigned int.

  ~ > perl -MDevel::Peek -e 'Dump 0xFFFFFFFF' 
  SV = IV(0x8133314) at 0x8125068
    REFCNT = 1
    FLAGS = (IOK,READONLY,pIOK,IsUV)
    UV = 4294967295

(Larger values get coerced to doubles.)

And Perl's shift *always* uses an unsigned int, except 
under 'use integer'.

  ~ > perl -le 'print 0xFFFFFFFF >> 31'
  1
  ~ > perl -Minteger -le 'print 0xFFFFFFFF >> 31'
  -1

It's just that shifting by >= the width of the type
is a 'mistake' and has no effect.

  ~ > perl -le 'print 0x0F >> 32'
  15

The equivalent C produces the same result, but gcc will
generate a warning, and maybe perl should as well.

Either way, if you want zero, just use a literal zero.

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


------------------------------

Date: Sun, 6 Oct 2002 22:38:45 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Is this a bug in perl?
Message-Id: <Pine.LNX.4.40.0210062221130.28961-100000@lxplus076.cern.ch>

On Oct 6, Steve Grazzini inscribed on the eternal scroll:

> It's just that shifting by >= the width of the type
> is a 'mistake'

Interesting, thanks - it's not an issue I'd tangled with before in
Perl (another of those "answers to questions that I hadn't realised
I wanted to ask" ;-)

> and has no effect.

Well, the 5.8.0 perlop pod says:

 The result of overflowing the range of the integers is undefined
 because it is undefined also in C. In other words, using 32-bit
 integers, 1 << 32 is undefined. Shifting by a negative number of bits
 is also undefined.

So it seems we shouldn't actually rely on it having no effect.

all the best



------------------------------

Date: 6 Oct 2002 16:42:30 -0700
From: kazchan@curio-city.com (kazchan)
Subject: Re: Open File problem
Message-Id: <3baaab4f.0210061542.3c13aea1@posting.google.com>

Thank you for many people who helped me.  Finally, I have finished the script.


------------------------------

Date: Sun, 06 Oct 2002 18:11:12 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: regex o modifier
Message-Id: <41%n9.40008$YI.8860869@twister.nyc.rr.com>

Roy Smith <roy@panix.com> wrote:
> I'm not meaning to start a language war here, but in Python, 
> I would do something like:
> 
> # Pre-compile all the regexes once
> compiledFilters = []
> for filter in filters:
>     compiledFilters.append (re.compile (filter))
 ...

> # Use the compiled versions each time through the main loop
> for cf in compiledFilters:
>    if cf.search (message):
>       return
 ...

> Is there anything similar in Perl?

Not only is there something similar:

  # Pre-compile all the regexes once
  my @compiled_filters = map qr/$_/, @filters;
  
  ...

  # Use the compiled versions each time through the main loop
  for my $cf (@compiled_filters) {
    return 1 if $message =~ /$cf/;
  }

But your question is "frequently asked":

  $ perldoc -q 'many regular expressions'
  Found in /usr/local/lib/perl5/5.8.0/pod/perlfaq6.pod
       How do I efficiently match many regular expressions at
       once?

And not only is it an FAQ, but the answer gets auto-posted to 
this group every few months:

  http://groups.google.com/groups?q=perlfaq+spiffy
 
And (sorry, this is getting bombastic :) not only is it posted 
every few months... it was posted this morning:

  <anpjgh$q5i$1@reader1.panix.com>


HTH
-- 
Steve
 
perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


------------------------------

Date: Sun, 06 Oct 2002 21:41:13 GMT
From: Darin McBride <darin@naboo.to.org.no.spam.for.me>
Subject: Re: regex o modifier
Message-Id: <Z52o9.484086$Ag2.19571060@news2.calgary.shaw.ca>

Roy Smith wrote:

> I've got a code fragment that looks like:
> 
>     foreach $filter (@filters) {
>         if ($message =~ m/$filter/) {
>             return;
>         }
>      }
> 
> Because a different regex is used each time through the loop, I pay for
> a regex compile every time, and the /o flag won't help me.  Is there any
> way to optimize this so all the regexes get compiled once, and saved?
> 
> I'm not meaning to start a language war here, but in Python, I would do
> something like:
> 
> # Pre-compile all the regexes once
> compiledFilters = []
> for filter in filters:
>     compiledFilters.append (re.compile (filter))
> 
> [...]
> 
> # Use the compiled versions each time through the main loop
> for cf in compiledFilters:
>    if cf.search (message):
>       return
> 
> Is there anything similar in Perl?
> 
> I realize I could build one huge composite regex by pasting all the
> individual ones together with "|", but I can't do that.  The individual
> regexes will be arbitrary strings read from an external source, and
> stuff like \1 would break.

I'm sure this has already been discussed quite recently here.  In fact,
it's probably one of those FAQ postings.  Try looking for the following
message ID: <anpjgh$q5i$1@reader1.panix.com>  (Use google if your
newsreader can't look up by message ID.)

-- 
To reply, please remove the obvious spam filter


------------------------------

Date: Sun, 06 Oct 2002 18:41:49 -0400
From: Roy Smith <roy@panix.com>
Subject: Re: regex o modifier
Message-Id: <roy-E3353D.18414906102002@reader1.panix.com>

Darin McBride <darin@naboo.to.org.no.spam.for.me> wrote:
> I'm sure this has already been discussed quite recently here.  In fact,
> it's probably one of those FAQ postings.  Try looking for the following
> message ID: <anpjgh$q5i$1@reader1.panix.com>  (Use google if your
> newsreader can't look up by message ID.)

That's exactly what I was looking for.  Thanks for the pointer!


------------------------------

Date: 6 Oct 2002 14:40:51 -0700
From: jeannot@gmavt.net (Jean Gagnon)
Subject: Re: Socket server & client only connect on same machine! (IO::Socket::INET->new)
Message-Id: <981d6b93.0210061340.400bcd95@posting.google.com>

That was it Thomas. 
Thanks!!!


------------------------------

Date: Sun, 06 Oct 2002 20:53:56 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: || versus OR
Message-Id: <Ep1o9.20679$Lg2.5545938@news2.news.adelphia.net>

"Aaron Simmons" <asimmons@mitre.org> wrote in message
news:anicri$rr1$1@newslocal.mitre.org...
> Here's one that burned me bad once:
> ##############################
> #########
> # Test #1--$input_name defined
> #########
> $input_name = 'Bob';
>
> $name_t1   = $input_name || 'Aaron';
> $name_t1_2 = $input_name or 'Aaron';
>
> print "name_t1:$name_t1\n";
> print "name_t1_2:$name_t1_2\n";
>
> #########
> # Test #2--$input_name2 defined
> #########
>
> $name_t2   = $input_name2 || 'Aaron';
> $name_t2_2 = $input_name2 or 'Aaron';
>
> print "name_t2:$name_t2\n";
> print "name_t2_2:$name_t2_2\n";
> ##############################
>
> With test#2, $name_t2_2 does not get assigned 'Aaron'
>
> -Aaron
Ahhh...the light goes on!  : )




------------------------------

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 3926
***************************************


home help back first fref pref prev next nref lref last post