[23552] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5760 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 6 18:10:50 2003

Date: Thu, 6 Nov 2003 15:10:15 -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           Thu, 6 Nov 2003     Volume: 10 Number: 5760

Today's topics:
    Re: I think what I need is a backreference but it doesn (Sara)
    Re: I think what I need is a backreference but it doesn (Sara)
    Re: I think what I need is a backreference but it doesn <pinyaj@rpi.edu>
    Re: I think what I need is a backreference but it doesn <pinyaj@rpi.edu>
    Re: math operations <fJogham@yahoo.com>
        nested loop. <spikeywan@bigfoot.com.delete.this.bit>
    Re: nested loop. <spikeywan@bigfoot.com.delete.this.bit>
    Re: nested loop. <asu1@c-o-r-n-e-l-l.edu>
    Re: nested loop. (Tad McClellan)
    Re: nested loop. <edady2002@yahoo.com>
    Re: Newbie gets Internal Server Error, among others (Jessica Smith)
    Re: Newbie gets Internal Server Error, among others (Tad McClellan)
        Perl Module DBD::ORACLE (polarbear)
    Re: problem with if-else assignment in text database (Vumani Dlamini)
    Re: problem with if-else assignment in text database (Tad McClellan)
        Regex that matches anything except a specific string (Richard Anderson)
    Re: Regex that matches anything except a specific strin <davido@pacifier.com>
    Re: Regex that matches anything except a specific strin <pinyaj@rpi.edu>
        Republicans can't even run a web server much less the c <superdude@flavorcountry.com>
    Re: what language is this? <syscjm@gwu.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 6 Nov 2003 11:06:03 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: I think what I need is a backreference but it doesn't ever match
Message-Id: <776e0325.0311061106.6db0d9a7@posting.google.com>

Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SGI.3.96.1031106004020.55498A-100000@vcmr-64.server.rpi.edu>...
> [posted & mailed]
> 
> On 5 Nov 2003, Sara wrote:
> 
> >For example, I have
> >
> >CAT1 
> >DOG2
> >MOUSE
> >EEL
> >CAT1 is ALFIE
> >DOG2 is FRED
> >
> >Say the result I want is
> >
> >CAT1 is ALFIE
> >DOG2 is FRED
> >MOUSE
> >EEL
> >
> >I tried something like:
> >
> > s/^(\w+\d)(.+)\n\1 is ([^\n]+)\n/$1 is $3$2/gsm;
> 
> It will match, but it won't match ALL the cases you want.  The reason is
> because the regex will have matched PAST "DOG2" after it's finished
> substituting "CAT1".  One solution is to use look-aheads, which allow you
> to match things in a string without actually consuming them in the string.
> 
> In case you don't know what I meant, let me give another example:
> 
>   $s = "abc def ghi abc ghi";
>   $s =~ s/(\S+)(.*?)\1/$1($2)/g;
> 
> This turns $s into "abc(def ghi) ghi".  It doesn't do anything with the
> ghi...ghi pair, because the regex reads "abc def ghi abc", so the next
> time the regex tries matching, there are no matches starting at any point
> in the string past the remaining " ghi".
> 
> Here's one way to do it with look-aheads in ONE regex:
> 
>   s{
>     ^ (\w+\d)
>     (?:
>       (?= \n (?: .* \n )* \1 \x20 is \x20 (.+) )
>       |
>       \x20 is \x20 .+ \n
>     )
>   }{ $2 ? "$1 is $2" : "" }egmsx;
> 
> There's a bit of work in there.  Basically, the regex matches one of two
> things.  If it matches "FOO1 is BLAH\n", it replaces that with nothing.
> Otherwise, if it matches "FOO1" and sees that a newline, followed by some
> lines, followed by "FOO1 is BLAH", it CAPTURES the "BLAH", and replaces
> the original "FOO1" with "FOO1 is BLAH".
> 
> The /e is needed because the replacement is code to be executed, and the
> /x is there to allow me to write the regex with abundant whitespace.
> (That's why ACTUAL spaces have been replaced with \x20.)

  .
  .  
  .


> Here's one way to do it with look-aheads in ONE regex:
> 
>   s{
>     ^ (\w+\d)
>     (?:
>       (?= \n (?: .* \n )* \1 \x20 is \x20 (.+) )
>       |
>       \x20 is \x20 .+ \n
>     )
>   }{ $2 ? "$1 is $2" : "" }egmsx;

# ow my head hurts now....
> 

I see what you're after here and I like it- I'm trying to get it to
wotrk thanks for taking the time to think this throught and document
it.

OK there is a lot of new syntax in here. I read in Camel that ?= is "a
zero-width positive lookahead assertion" [1]. The meaning of a (ZWPLA)
isn't intuitively obvious to me, but I think it's what you refer to as
"the look-ahead"? So for those cases, anything in parens that is
preceeded by the ?= will NOT be consumed, but WILL be considered for
the match.

(?: ) is "the Grouper"? [also 1] 

It's the same as ( ) except it creates no $n var for the result? Seems
like sort of like an oddball operator; not not loose the extra syntax
and just ignore that particular $n? But ok..

As a point of readability, how about something like:

  
  s/^(\w+\d)(.+)\n\1 is ([^\n]+)\n/$1 is $3$2/gsm while $&;

I realize it might take more tweaks since each iteration starts at the
top, so you'd have to be careful that it didn't match the same line
over and over. But stylistically, is this sort of approach such a bad
idear? Its pretty readable!


Thanks again,
G





[1] Camel Edition 2 p 68


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

Date: 6 Nov 2003 11:18:02 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: I think what I need is a backreference but it doesn't ever match
Message-Id: <776e0325.0311061118.29173c5e@posting.google.com>

Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SGI.3.96.1031106004020.55498A-100000@vcmr-64.server.rpi.edu>...
> [posted & mailed]
> 
> On 5 Nov 2003, Sara wrote:
> 
> >For example, I have
> >
> >CAT1 
> >DOG2
> >MOUSE
> >EEL
> >CAT1 is ALFIE
> >DOG2 is FRED
> >
> >Say the result I want is
> >
> >CAT1 is ALFIE
> >DOG2 is FRED
> >MOUSE
> >EEL
> >
> >I tried something like:
> >
> > s/^(\w+\d)(.+)\n\1 is ([^\n]+)\n/$1 is $3$2/gsm;
> 
> It will match, but it won't match ALL the cases you want.  The reason is
> because the regex will have matched PAST "DOG2" after it's finished
> substituting "CAT1".  One solution is to use look-aheads, which allow you
> to match things in a string without actually consuming them in the string.
> 
> In case you don't know what I meant, let me give another example:
> 
>   $s = "abc def ghi abc ghi";
>   $s =~ s/(\S+)(.*?)\1/$1($2)/g;
> 
> This turns $s into "abc(def ghi) ghi".  It doesn't do anything with the
> ghi...ghi pair, because the regex reads "abc def ghi abc", so the next
> time the regex tries matching, there are no matches starting at any point
> in the string past the remaining " ghi".
> 
> Here's one way to do it with look-aheads in ONE regex:
> 
>   s{
>     ^ (\w+\d)
>     (?:
>       (?= \n (?: .* \n )* \1 \x20 is \x20 (.+) )
>       |
>       \x20 is \x20 .+ \n
>     )
>   }{ $2 ? "$1 is $2" : "" }egmsx;
> 
> There's a bit of work in there.  Basically, the regex matches one of two
> things.  If it matches "FOO1 is BLAH\n", it replaces that with nothing.
> Otherwise, if it matches "FOO1" and sees that a newline, followed by some
> lines, followed by "FOO1 is BLAH", it CAPTURES the "BLAH", and replaces
> the original "FOO1" with "FOO1 is BLAH".
> 
> The /e is needed because the replacement is code to be executed, and the
> /x is there to allow me to write the regex with abundant whitespace.
> (That's why ACTUAL spaces have been replaced with \x20.)

Hmm curiously I changed 

     s/^(\w+\d)(.+)\n\1 ...

 to

     s/^(\w+\d)(?=.+)\n\1 ...

and now instead of one match I get NONE! Didn't see THAT coming :) How
could ?= have caused the string NOT TO MATCH? It shouldn't change the
matching functionality would it?

G


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

Date: Thu, 6 Nov 2003 15:34:35 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Sara <genericax@hotmail.com>
Subject: Re: I think what I need is a backreference but it doesn't ever match
Message-Id: <Pine.SGI.3.96.1031106153026.62394A-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 6 Nov 2003, Sara wrote:

>Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:<Pine.SGI.3.96.1031106004020.55498A-100000@vcmr-64.server.rpi.edu>...
>> [posted & mailed]
>> 
>> Here's one way to do it with look-aheads in ONE regex:
>> 
>>   s{
>>     ^ (\w+\d)
>>     (?:
>>       (?= \n (?: .* \n )* \1 \x20 is \x20 (.+) )
>>       |
>>       \x20 is \x20 .+ \n
>>     )
>>   }{ $2 ? "$1 is $2" : "" }egmsx;

Oops!  Get rid of the /s modifier!  That broke it.  Taking the /s modifier
out makes it work.

>OK there is a lot of new syntax in here. I read in Camel that ?= is "a
>zero-width positive lookahead assertion" [1]. The meaning of a (ZWPLA)
>isn't intuitively obvious to me, but I think it's what you refer to as
>"the look-ahead"? So for those cases, anything in parens that is
>preceeded by the ?= will NOT be consumed, but WILL be considered for
>the match.

Yeah... (?=...) basically matches, and if it matches, it backtracks to
where it started to match.  It looks ahead for the pattern, but doesn't
CONSUME it.

>(?: ) is "the Grouper"? [also 1] 
>
>It's the same as ( ) except it creates no $n var for the result? Seems
>like sort of like an oddball operator; not not loose the extra syntax
>and just ignore that particular $n? But ok..

Yes.  (?:...) groups, but doesn't capture.  It also lets you put in
modifiers (to turn them on or off), like (?i:...) and (?s-i:...).

-- 
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: Thu, 6 Nov 2003 15:38:52 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Sara <genericax@hotmail.com>
Subject: Re: I think what I need is a backreference but it doesn't ever match
Message-Id: <Pine.SGI.3.96.1031106153545.62394B-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 6 Nov 2003, Sara wrote:

>Hmm curiously I changed 
>
>     s/^(\w+\d)(.+)\n\1 ...
>
> to
>
>     s/^(\w+\d)(?=.+)\n\1 ...

It breaks because the (?=.+) looks ahead to match one or more characters.
Once that succeeds, the regex goes back to where it was in the string.  It
then looks for a newline, and what was matched into $1.  So unless you
have

  FOO1
  FOO1 is BAR

then it won't work.

-- 
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: Fri, 07 Nov 2003 06:48:59 +1100
From: Fred <fJogham@yahoo.com>
Subject: Re: math operations
Message-Id: <3FAAA5AB.5020307@yahoo.com>

Anno Siegel wrote:
> Fred  <news@group.com> wrote in comp.lang.perl.misc:
> 
>>Hello
>>I need to do some calculations using math operator like
>>element of
>>overlap
>>summation
>>and others in this link 
>>http://whatis.techtarget.com/definition/0,,sid9_gci803019,00.html
> 
> 
> That site describes about 120 standard (and less-than-standard) mathe-
> matical symbols.
> 
> As a side note, they demonstrate the summation symbol using a divergent
> infinite series (sum( 1/n, n = 1 .. infinity)).  This isn't outright
> wrong, but it doesn't bode well for the mathematical awareness of the
> authors.
> 
> 
>>does perl support those operations? is there an add on module or use 
>>another language?
> 
> 
> Do you really expect someone to go through them all and check what Perl
> supports and what it doesn't?
> 
no, I just want to know if I can do the following things with perl:

I have many arrays with their elements being bits, e.g. "010000".
I need to use bitwise operators ( and, or, xor ) to evaluate sections of 
the arrays against each other as well as against other sections in the 
same array.

some of the math functions I need to use are
intersect
element of
summation
and in the future, may be few more.
sure I can manage to write my own functions but since I don't know what 
other functions I may need in the future, I wanted to know if by user 
Perl I may have some difficult time with the project. or would it be 
easier to get some help of another language like octave.
thanks








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

Date: Thu, 6 Nov 2003 16:39:50 -0000
From: "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit>
Subject: nested loop.
Message-Id: <bodtjh$109$1@newshost.mot.com>

Guys,

I have a while(1) loop, that contains another while(1) loop.

If I put a next command in the outer  loop, everything is fine. As soon as I
added a next command to the inner loop, everything went wrong. Is the next
acting on the outer loop, rather than the inner one, and if so, how can I
make it act on the inner one?

Thanks.
-- 
R.
GPLRank +79.699




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

Date: Thu, 6 Nov 2003 16:49:30 -0000
From: "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit>
Subject: Re: nested loop.
Message-Id: <bodu5l$1q8$1@newshost.mot.com>

Ah! Found the problem!

Sorry.

(Because I was using a while(1) loop, I was manually incrementing my
counter, and when I inserted the next command, the counter was never
incremented, so the loop got stuck on the same operator. D'oh!)
-- 
R.
GPLRank +79.699

> Guys,
>
> I have a while(1) loop, that contains another while(1) loop.
>
> If I put a next command in the outer  loop, everything is fine. As soon as
I
> added a next command to the inner loop, everything went wrong. Is the next
> acting on the outer loop, rather than the inner one, and if so, how can I
> make it act on the inner one?
>
> Thanks.
> -- 
> R.
> GPLRank +79.699
>
>




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

Date: 6 Nov 2003 20:03:22 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: nested loop.
Message-Id: <Xns942B99292EB6Easu1cornelledu@132.236.56.8>

"Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit> wrote in 
news:bodu5l$1q8$1@newshost.mot.com:

> Ah! Found the problem!
> 
> Sorry.
> 
> (Because I was using a while(1) loop, I was manually incrementing my
> counter, and when I inserted the next command, the counter was never
> incremented, so the loop got stuck on the same operator. D'oh!)

We are so happy for you. However, please read the posting quidelines 
(available at http://mail.augustmail.com/~tadmc/clpmisc.shtml). Post code 
instead of trying to verbally describe your code and then summarize your 
problem if you want anyone else to be able to help you.

Sinan.


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

Date: Thu, 6 Nov 2003 15:35:34 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: nested loop.
Message-Id: <slrnbqlfl6.3ce.tadmc@magna.augustmail.com>

A. Sinan Unur <asu1@c-o-r-n-e-l-l.edu> wrote:
> "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit> wrote in 
> news:bodu5l$1q8$1@newshost.mot.com:

>> Sorry.

> However, please read the posting quidelines 


I think you are "talking to the hand" in this case.  :-(


   Message-ID: <ajvra9$3b3$1@newshost.mot.com>

   Message-ID: <ak27sg$o0$1@newshost.mot.com>


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 07 Nov 2003 09:01:47 +1100
From: Edo <edady2002@yahoo.com>
Subject: Re: nested loop.
Message-Id: <3FAAC4CB.5090805@yahoo.com>

Richard S Beckett wrote:
> Guys,
> 
> I have a while(1) loop, that contains another while(1) loop.
> 
> If I put a next command in the outer  loop, everything is fine. As soon as I
> added a next command to the inner loop, everything went wrong. Is the next
> acting on the outer loop, rather than the inner one, and if so, how can I
> make it act on the inner one?
> 
> Thanks.

while (1) {
   while (1) { next };
next;
}

			



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

Date: 6 Nov 2003 11:49:52 -0800
From: jessis@cobweb.net (Jessica Smith)
Subject: Re: Newbie gets Internal Server Error, among others
Message-Id: <89ed09a8.0311061149.6c0482d8@posting.google.com>

When I do a "where perl" it tells me usr/bin/perl, which is right
where I'm telling the script to look. I'm on Mac OS 10.2.8 as well,
using Perl 5.6.0, which was already on my machine.

I am SO frustrated. Someone else said something about line endings...
I don't know what that's all about. Any other ideas, or should I just
continue beating my head against my lovely corkboard partition here?

Thanks.


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

Date: Thu, 6 Nov 2003 15:37:44 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie gets Internal Server Error, among others
Message-Id: <slrnbqlfp8.3ce.tadmc@magna.augustmail.com>

Jessica Smith <jessis@cobweb.net> wrote:

> When I do a "where perl" it tells me usr/bin/perl, which is right
                                      ^^
                                      ^^
> where I'm telling the script to look.


Where is the leading slash?

    /usr/bin/perl


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 6 Nov 2003 14:53:24 -0800
From: mp34ken@hotmail.com (polarbear)
Subject: Perl Module DBD::ORACLE
Message-Id: <1fd7a467.0311061453.522491a9@posting.google.com>

Friends. 

When I attempt to install the DBD::ORACLE modual it hangs after one
line of output.

I have installed several other modules including DBI with out
problems. Has anyone seen this.

-Ken



[logger] oracle> perl -V
Summary of my perl5 (revision 5.0 version 8 subversion 0)
configuration:
  Platform:
    osname=solaris, osvers=2.8, archname=sun4-solaris
    uname='sunos solaris 5.8 generic_108528-11 sun4u sparc
sunw,ultra-5_10 '
    config_args='-Dcc=gcc -B/usr/ccs/bin/'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc -B/usr/ccs/bin/', ccflags ='-fno-strict-aliasing
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O',
    cppflags='-fno-strict-aliasing'
    ccversion='', gccversion='3.1', gccosandvers='solaris2.8'
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
    d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc -B/usr/ccs/bin/', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lgdbm -ldl -lm -lc
    perllibs=-lsocket -lnsl -ldl -lm -lc
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
    cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  Compile-time options: USE_LARGE_FILES
  Built under solaris
  Compiled at Jul 22 2002 02:55:19
  @INC:
    /usr/local/lib/perl5/5.8.0/sun4-solaris
    /usr/local/lib/perl5/5.8.0
    /usr/local/lib/perl5/site_perl/5.8.0/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.8.0
    /usr/local/lib/perl5/site_perl
    .


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

Date: 6 Nov 2003 09:39:41 -0800
From: dvumani@hotmail.com (Vumani Dlamini)
Subject: Re: problem with if-else assignment in text database
Message-Id: <4b35f3c9.0311060939.7d2304ba@posting.google.com>

Thanks guys. I have never used "use warnings" before. I am what you
call a gatecrasher to Perl. A problem came up which I thought Perl
could do better than text processing facilities in statistical
software.

Thanks again guys, hope you don't get tired of me, like Ted.

Vumani


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

Date: Thu, 6 Nov 2003 15:27:59 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: problem with if-else assignment in text database
Message-Id: <slrnbqlf6v.3ce.tadmc@magna.augustmail.com>

Vumani Dlamini <dvumani@hotmail.com> wrote:


> Thanks again guys, hope you don't get tired of me, like Ted.


To avoid becoming wearysome, simply see the Posting Guidelines 
that are posted here frequently...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 6 Nov 2003 11:11:43 -0800
From: gg.2.starfire@spamgourmet.com (Richard Anderson)
Subject: Regex that matches anything except a specific string
Message-Id: <a1da29b3.0311061111.337b6ace@posting.google.com>

I am trying to feed a regular expression to a mail processing program that
matches every string except a specific string.  For example, I want a regex
that does not match richard@richard-anderson.org but matches any other
string.  If I were writing a Perl program, I would just do this:

if ($address !~ /^richard\@richard-anderson\.org$/) { print "Spam\n" }

but I am not able to modify the source code of the program I am using.

I haven't been able to do this using the complement metacharacter (^).  I'd
accept a solution that matches anything except an anagram of
richard@richard-anderson.org

P.S. This is actually a Python regex, but Python's regexes are very similar
to Perl's regexes.


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

Date: Thu, 06 Nov 2003 20:30:19 GMT
From: "Dave Oswald" <davido@pacifier.com>
Subject: Re: Regex that matches anything except a specific string
Message-Id: <vbyqb.236$Da5.253433@news3.news.adelphia.net>

"Richard Anderson" <gg.2.starfire@spamgourmet.com> wrote:

> I am trying to feed a regular expression to a mail processing program that
> matches every string except a specific string.  For example, I want a
regex
> that does not match richard@richard-anderson.org but matches any other
> string.  If I were writing a Perl program, I would just do this:
>
> if ($address !~ /^richard\@richard-anderson\.org$/) { print "Spam\n" }
>
> but I am not able to modify the source code of the program I am using.
>
> I haven't been able to do this using the complement metacharacter (^).
I'd
> accept a solution that matches anything except an anagram of
> richard@richard-anderson.org
>
> P.S. This is actually a Python regex, but Python's regexes are very
similar
> to Perl's regexes.

Your question has nothing to do with Perl, and the Perlish solution won't
work for Python unless Python's regexp is identical to Perl's.  "Very
similar" isn't close enough.

That said, in Perl you would write a regexp to look like this:
/^(?!richard\@richard-anderson\.org)$/

That's a negative lookahead assertion.




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

Date: Thu, 6 Nov 2003 15:42:26 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Regex that matches anything except a specific string
Message-Id: <Pine.SGI.3.96.1031106154037.62394D-100000@vcmr-64.server.rpi.edu>

On 6 Nov 2003, Richard Anderson wrote:

>I am trying to feed a regular expression to a mail processing program that
>matches every string except a specific string.  For example, I want a regex
>that does not match richard@richard-anderson.org but matches any other
>string.  If I were writing a Perl program, I would just do this:
>
>if ($address !~ /^richard\@richard-anderson\.org$/) { print "Spam\n" }
>
>but I am not able to modify the source code of the program I am using.

I don't usually answer non-Perl questions in this newsgroup, but I'll
pretend you're asking how to turn

  if ($str !~ /^pat$/) { ... }

into a match using =~ instead.

  if ($str =~ /^(?!richard\@richard-anderson\.org$)/) { ... }

-- 
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: Thu, 06 Nov 2003 13:42:53 -0700
From: Superdude <superdude@flavorcountry.com>
Subject: Republicans can't even run a web server much less the country.
Message-Id: <o5qdnSwD2KfULzeiRVn-gg@comcast.com>

http://www.linuxjournal.com/article.php?sid=7239&mode=thread&order=0



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

Date: Thu, 06 Nov 2003 11:29:48 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: what language is this?
Message-Id: <3FAA76FC.6080500@gwu.edu>

Abigail wrote:
> Chris Mattern (syscjm@gwu.edu) wrote on MMMDCCXVIII September MCMXCIII in
> <URL:news:3FA95E7C.804@gwu.edu>:
> :}  Fred wrote:
> :} > hello
> :} > I am trying to understand a lettle about a code in a language which is 
> :} > not perl. would someone know what language it is?
> :} > 
> :} > e.g. in perl
> :} > my $a = 0b100001;
> :} > my $b = 0b010001;
> :} > the logic operator for xOr is "^"
> :} > 
> :} > 
> :} > in this language it is
> :} > |xOr(a,b)|
> :} > 
> :}  
> :}  Fred, you've given virtually no data.  What you've described could
> :}  cover literally hundreds (hell, thousands) of languages, *including*
> :}  Perl if the program in question defined an "xOr" subroutine.  Try
> :}  giving a couple of dozen lines of code as an example; it might be
> :}  possible to determine the language from that.
> 
> 
> Well, it might be possible to define an 'xOr' subrouting in Perl, it's
> not possible to define your own operators. And considering Perl doesn't
> have unary |, or any circumfix operators, I don't see how the quoted
> line could be valid Perl. (Input to filters doesn't count).
> 
It's not entirely clear to me that the vertical bars are part of the
statement and not just his whimsical way of quoting it.

                 Chris Mattern



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

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


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