[32016] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3280 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 8 18:09:22 2011

Date: Tue, 8 Feb 2011 15:09:07 -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           Tue, 8 Feb 2011     Volume: 11 Number: 3280

Today's topics:
        [OT] other forms of the word in english <hollow.quincy@gmail.com>
        can someone help me with this baffling regex ? <spydox@gmail.com>
    Re: can someone help me with this baffling regex ? <willem@turtle.stack.nl>
    Re: can someone help me with this baffling regex ? <uri@StemSystems.com>
    Re: can someone help me with this baffling regex ? <spydox@gmail.com>
    Re: can someone help me with this baffling regex ? <uri@StemSystems.com>
    Re: How find all overlapping pattern? <hjp-usenet2@hjp.at>
    Re: How find all overlapping pattern? <cartercc@gmail.com>
    Re: How find all overlapping pattern? <jl_post@hotmail.com>
    Re: How find all overlapping pattern? sln@netherlands.com
        How to invoke a function inside regular expression subs <ignoramus908@NOSPAM.908.invalid>
    Re: How to invoke a function inside regular expression  <m@rtij.nl.invlalid>
    Re: How to invoke a function inside regular expression  <nospam.gravitalsun@hotmail.com.nospam>
    Re: How to invoke a function inside regular expression  <ignoramus908@NOSPAM.908.invalid>
    Re: Is there an ARRAY designator for REGEX vals? <edmills@gmail.com>
    Re: upload module to CPAN (http client) <loofort@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 8 Feb 2011 14:31:54 -0800 (PST)
From: Hollow Quincy <hollow.quincy@gmail.com>
Subject: [OT] other forms of the word in english
Message-Id: <0569b182-a89e-4cee-adc9-49bba9fd01ec@n10g2000yqf.googlegroups.com>

Hi,

I'm looking for an aplication / dictionary that would find other forms
of the word in english.
E.g. I would give word "love" it will returns loved, loving, lovely
etc.
Have you ever met something like that ?

Thanks for help


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

Date: Tue, 8 Feb 2011 12:14:29 -0800 (PST)
From: Spydo <spydox@gmail.com>
Subject: can someone help me with this baffling regex ?
Message-Id: <c889b2c5-b649-4888-bd9d-7f4edd025812@m16g2000prc.googlegroups.com>

Hello experts:

Honestly it's very unusual that I can't figure out a tite lil' regex
to solve a substitution, but this one has me baffled.. And it looks
simple..

I'm trying to remove ALL but the last dot in a scalar.

So I want to replace

'cat.dog.mouse.eel.txt'

with

'catdogmouseeel.txt'

I've tried a bunch of approaches, and one actually WORKS but has
warnings...

WORKS but throws warnings seemingly for every extra dot:

s/\.(?=[^\.]*\.)/$1/g;
 
DB<7>
Use of uninitialized value in substitution iterator at x.pl line 5.
 at x.pl line 5
Use of uninitialized value in substitution iterator at x.pl line 5.
 at x.pl line 5
Use of uninitialized value in substitution iterator at x.pl line 5.
 at x.pl line 5
  DB<7> x
$_
0  'catdogmouseeel.txt'


DOES NOT WORK- Im not really sure why:
 s/([^\.]*)\.?=(.*\.)/$1$2/g;

(does nothing)


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

Date: Tue, 8 Feb 2011 20:28:47 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: can someone help me with this baffling regex ?
Message-Id: <slrnil39rv.1u1q.willem@turtle.stack.nl>

Spydo wrote:
) Hello experts:
)
) Honestly it's very unusual that I can't figure out a tite lil' regex
) to solve a substitution, but this one has me baffled.. And it looks
) simple..
)
) I'm trying to remove ALL but the last dot in a scalar.
)
) So I want to replace
)
) 'cat.dog.mouse.eel.txt'
)
) with
)
) 'catdogmouseeel.txt'
)
) I've tried a bunch of approaches, and one actually WORKS but has
) warnings...
)
) WORKS but throws warnings seemingly for every extra dot:
)
) s/\.(?=[^\.]*\.)/$1/g;

What's that $1 for ?  There is no capture.

(The ?= makes it a postmatch, instead of capturing parens.)


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


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

Date: Tue, 08 Feb 2011 15:46:01 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: can someone help me with this baffling regex ?
Message-Id: <877hdatfue.fsf@quad.sysarch.com>

>>>>> "W" == Willem  <willem@turtle.stack.nl> writes:

  W> Spydo wrote:
  W> ) I'm trying to remove ALL but the last dot in a scalar.
  W> )
  W> ) WORKS but throws warnings seemingly for every extra dot:
  W> )
  W> ) s/\.(?=[^\.]*\.)/$1/g;

  W> What's that $1 for ?  There is no capture.

yep.

  W> (The ?= makes it a postmatch, instead of capturing parens.)

and this is the same thing but simplified and it seems to work:

echo 'foo.bar.baz.quux' | perl -wlpe 's/\.(?=.*\.)//g'
foobarbaz.quux

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Tue, 8 Feb 2011 12:59:26 -0800 (PST)
From: Spydo <spydox@gmail.com>
Subject: Re: can someone help me with this baffling regex ?
Message-Id: <215897c0-2b94-4431-99b3-967283948cbc@n16g2000prc.googlegroups.com>

On Feb 8, 3:46=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> >>>>> "W" =3D=3D Willem =A0<wil...@turtle.stack.nl> writes:
>
> =A0 W> Spydo wrote:
> =A0 W> ) I'm trying to remove ALL but the last dot in a scalar.
> =A0 W> )
> =A0 W> ) WORKS but throws warnings seemingly for every extra dot:
> =A0 W> )
> =A0 W> ) s/\.(?=3D[^\.]*\.)/$1/g;
>
> =A0 W> What's that $1 for ? =A0There is no capture.
>
> yep.
>
> =A0 W> (The ?=3D makes it a postmatch, instead of capturing parens.)
>
> and this is the same thing but simplified and it seems to work:
>
> echo 'foo.bar.baz.quux' | perl -wlpe 's/\.(?=3D.*\.)//g'
> foobarbaz.quux
>
> uri
>
> --
> Uri Guttman =A0------ =A0u...@stemsystems.com =A0-------- =A0http://www.s=
ysarch.com--
> ----- =A0Perl Code Review , Architecture, Development, Training, Support =
------
> --------- =A0Gourmet Hot Cocoa Mix =A0---- =A0http://bestfriendscocoa.com=
---------

Thanks guys

I think I see what you mean the ?=3D wipes out the match? Still- I would
have expected $1 to be just '', but I guess its actually undef.

I don't use ?=3D often and when I do it usually doesn't seem to do what
I expected..


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

Date: Tue, 08 Feb 2011 16:09:09 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: can someone help me with this baffling regex ?
Message-Id: <87lj1qs07e.fsf@quad.sysarch.com>

>>>>> "S" == Spydo  <spydox@gmail.com> writes:

  S> On Feb 8, 3:46 pm, "Uri Guttman" <u...@StemSystems.com> wrote:
  >> >>>>> "W" == Willem  <wil...@turtle.stack.nl> writes:
  >> 
  >>   W> Spydo wrote:
  >>   W> ) I'm trying to remove ALL but the last dot in a scalar.
  >>   W> )
  >>   W> ) WORKS but throws warnings seemingly for every extra dot:
  >>   W> )
  >>   W> ) s/\.(?=[^\.]*\.)/$1/g;
  >> 
  >>   W> What's that $1 for ?  There is no capture.
  >> 
  >> yep.
  >> 
  >>   W> (The ?= makes it a postmatch, instead of capturing parens.)
  >> 
  >> and this is the same thing but simplified and it seems to work:
  >> 
  >> echo 'foo.bar.baz.quux' | perl -wlpe 's/\.(?=.*\.)//g'
  >> foobarbaz.quux

  S> I think I see what you mean the ?= wipes out the match? Still- I would
  S> have expected $1 to be just '', but I guess its actually undef.

why would it be ''? that is an empty string which could be a real grab
(just of 0 length). you need $1 to be undef to say it never was set by a
grab.

  S> I don't use ?= often and when I do it usually doesn't seem to do what
  S> I expected.

it is very simple. first, it is a zero width assertion which means it
doesn't eat chars from the data. you use other zero width assertions
like ^ and \b so this is the same. then it just matches what is at the
match point now and fails if it doesn't. just combine those two
properties and it is easy to get and use.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Tue, 8 Feb 2011 16:09:43 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How find all overlapping pattern?
Message-Id: <slrnil2n5n.12a.hjp-usenet2@hrunkner.hjp.at>

On 2011-02-07 16:46, ccc31807 <cartercc@gmail.com> wrote:
> On Feb 7, 10:31 am, Peng Yu <pengyu...@gmail.com> wrote:
>> $string="abcabcabc";
>> @findall = $string =~ /abcabc/g;
>> print scalar(@findall), "\n";
>>
>> The above commands will print 1 rather than 2. Because there are two
>> overlapping 'abcabc', I'd like to get 2. I'm wondering what is the
>> correct way to find all overlapping regexes. (Note that I gave
                                                 ^^^^^^^^^^^^^^^^
>> 'abcabc' as an example, but it could be any complex regex) Thanks!
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> You don't have to use a regular expression in a case like this. You
> can use index($string, $substring, $position) in a loop,

You did read what the OP wrote, did you?

	hp



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

Date: Tue, 8 Feb 2011 07:46:51 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: How find all overlapping pattern?
Message-Id: <70b20ab9-f2d6-4aec-802f-73e4a7713172@m16g2000prc.googlegroups.com>

On Feb 8, 10:09=A0am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> You did read what the OP wrote, did you?

I did, and I thought about it. Several times in the past few weeks,
I've had problems with REs acting poorly, and used other means to do
what I needed to do, primarily index() and substr().

My point was not that an RE can always be replaced by built in
functions, but that an RE can sometimes be replaced by built in
functions.

CC.


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

Date: Tue, 8 Feb 2011 11:02:17 -0800 (PST)
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: How find all overlapping pattern?
Message-Id: <bffe26b6-3a50-47e1-bcd9-cb8c68cd9795@z3g2000prz.googlegroups.com>

> On Feb 7, 8:31=A0am, Peng Yu <pengyu...@gmail.com> wrote:
>
> > $string=3D"abcabcabc";
> > @findall =3D $string =3D~ /abcabc/g;
> > print scalar(@findall), "\n";
>
> > The above commands will print 1 rather than 2. Because there are two
> > overlapping 'abcabc', I'd like to get 2. I'm wondering what is the
> > correct way to find all overlapping regexes. (Note that I gave
> > 'abcabc' as an example, but it could be any complex regex) Thanks!


On Feb 7, 9:02=A0am, "jl_p...@hotmail.com" <jl_p...@hotmail.com>
replied:
>
> =A0 =A0Here's one way to do it:
>
> =A0 =A0 =A0 while ($string =3D~ m/(abcabc)/g)
> =A0 =A0 =A0 {
> =A0 =A0 =A0 =A0 =A0push @findall, $1;
> =A0 =A0 =A0 =A0 =A0pos($string) =3D $-[0] + 1;
> =A0 =A0 =A0 }


   Hmmm... after reading the other replies, I think that:

      @findall =3D $string =3D~ /(?=3Dabcabc)/g;

(which uses a positive look-head) is probably the cleaner solution.

   Just my opinion.

   -- Jean-Luc


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

Date: Tue, 08 Feb 2011 11:07:47 -0800
From: sln@netherlands.com
Subject: Re: How find all overlapping pattern?
Message-Id: <uo43l65udo54cspgc87ca6oaa7fadrpj9h@4ax.com>

On Mon, 7 Feb 2011 22:24:25 +0000 (UTC), Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:

>On 2011-02-07, Peng Yu <pengyu.ut@gmail.com> wrote:
>> $string="abcabcabc";
>> @findall = $string =~ /abcabc/g;
>> print scalar(@findall), "\n";
>>
>> The above commands will print 1 rather than 2. Because there are two
>> overlapping 'abcabc', I'd like to get 2. I'm wondering what is the
>> correct way to find all overlapping regexes. (Note that I gave
>> 'abcabc' as an example, but it could be any complex regex) Thanks!
>
>Do not use RExes which "move the match point too far" (i.e., match
>more than one character).  In some situations 0-length match may cause
>a problem (non-intuitive semantic), but if the REx is ALWAYS matching
>0-length substring, the match rules are intuitive again.
>
>So use /(?=(abcabc))/g.
>

s/ALWAYS/ONLY/

Nice, and the behavior should be the same if quantifiers and/or
assertions are added.

-sln


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

Date: Tue, 08 Feb 2011 07:26:23 -0600
From: Ignoramus908 <ignoramus908@NOSPAM.908.invalid>
Subject: How to invoke a function inside regular expression substitution
Message-Id: <kP2dnXKoC-vi2czQnZ2dnUVZ_tmdnZ2d@giganews.com>

I would like to call a function on every match to regular expression. 

Say, every match of the following should invoke MyFunc on $1. Kind of like this

$my_string =~ s#<TD>(.*?)</TD>#<TD>&MyFunc( $1 )</TD>#g;

In other words, I want to substitute $1 with a result of a function
call. 

Can I do that in perl?

Thanks, guys!

i


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

Date: Tue, 8 Feb 2011 14:45:20 +0100
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: How to invoke a function inside regular expression substitution
Message-Id: <g0u728-ia7.ln1@news.rtij.nl>

On Tue, 08 Feb 2011 07:26:23 -0600, Ignoramus908 wrote:

> I would like to call a function on every match to regular expression.
> 
> Say, every match of the following should invoke MyFunc on $1. Kind of
> like this
> 
> $my_string =~ s#<TD>(.*?)</TD>#<TD>&MyFunc( $1 )</TD>#g;
> 
> In other words, I want to substitute $1 with a result of a function
> call.

perldoc perlre, in particular look at the 'e' modifier.

HTH,
M4


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

Date: Tue, 8 Feb 2011 15:58:10 +0200
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: Re: How to invoke a function inside regular expression substitution
Message-Id: <iiri65$10s5$1@ulysses.noc.ntua.gr>


while (my $my_string=<DATA>)
{
$my_string =~s|<TD>(.*?)</TD>|'<TD>'.MyFunc($^N).'</TD>'|ge;
print "$my_string";
}

sub MyFunc
{
"$_[0] is ".length($_[0])."bytes long"
}


__DATA__
<TD>hello</TD>
<TD>world</TD>
from
Perl 




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

Date: Tue, 08 Feb 2011 08:05:29 -0600
From: Ignoramus908 <ignoramus908@NOSPAM.908.invalid>
Subject: Re: How to invoke a function inside regular expression substitution
Message-Id: <MoednVveyMc00MzQnZ2dnUVZ_hqdnZ2d@giganews.com>

George and Martijn, this is AWESOME! Thanks!

i

On 2011-02-08, George Mpouras <nospam.gravitalsun@hotmail.com.nospam> wrote:
>
> while (my $my_string=<DATA>)
> {
> $my_string =~s|<TD>(.*?)</TD>|'<TD>'.MyFunc($^N).'</TD>'|ge;
> print "$my_string";
> }
>
> sub MyFunc
> {
> "$_[0] is ".length($_[0])."bytes long"
> }
>
>
> __DATA__
><TD>hello</TD>
><TD>world</TD>
> from
> Perl 
>
>


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

Date: Tue, 8 Feb 2011 11:55:03 -0800 (PST)
From: Ed Mills <edmills@gmail.com>
Subject: Re: Is there an ARRAY designator for REGEX vals?
Message-Id: <82ba27d3-5476-403e-9fb3-b4c712d75ee7@x4g2000prf.googlegroups.com>

On Jan 25, 3:15=A0pm, Sherm Pendley <sherm.pend...@gmail.com> wrote:
> Spydo <spy...@gmail.com> writes:
> > if not, it would be useful, since on-occasion I find I need ($1,$2,
> > $3, ... ,$n ) =A0which would be more concisely written @something..
>
> In list context, the match operator returns a list of matched subexp-
> ressions, as in:
>
> =A0 my @matches =3D $string =3D~ m/(foo)(bar)(baz)/;
>
> =A0 my ($foo, $bar, $baz) =3D m/(foo)(bar)(baz)/;
>
> Also possibly of interest, after a successful match, @- and @+ contain
> the start and end offsets of the match and any submatches.
>
> sherm--
>
> --
> Sherm Pendley
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0<h=
ttp://camelbones.sourceforge.net>
> Cocoa Developer

oh oh oh- this is an epiphany for me thank-you. I always wondered what
that n did you were a huge help!


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

Date: Tue, 8 Feb 2011 03:25:26 -0800 (PST)
From: Loofort <loofort@gmail.com>
Subject: Re: upload module to CPAN (http client)
Message-Id: <3d0391c7-33dc-47d0-af15-9f9eee7c8ecf@u3g2000vbe.googlegroups.com>

On 6 =D1=84=D0=B5=D0=B2, 15:20, "Peter J. Holzer" <hjp-usen...@hjp.at> wrot=
e:
> On 2011-02-05 22:48, Dr.Ruud <rvtol+use...@xs4all.nl> wrote:
>
> > On 2011-02-05 17:09, brian d foy wrote:
> >> In article
> >> <5964fa37-8869-43cd-a69e-37d1506d3...@r19g2000prm.googlegroups.com>,
> >> Loofort<loof...@gmail.com> =C2=A0wrote:
>
> >>> I think to prefix packages with "CTX" - meaning "context" since http
> >>> (and specially ftp) works in context - pass the cookies, understand
> >>> relative links, keep alive connections etc.
>
> >> PAUSE has some naming advice. There's not much context for CTX, so you
> >> might choose another top-level namespace :)
>
> >>https://pause.perl.org/pause/query?ACTION=3Dpause_namingmodules
>
> > "pause.perl.org uses an invalid security certificate."
>
> It's signed by CAcert. Your browser probably doesn't have the root
> certificate for that CA installed. You can get it fromhttp://www.cacert.o=
rg/index.php?id=3D3. (orhttps://www.cacert.org/index.php?id=3D3but there yo=
ur browser will
> complain about an invalid certificate, too).
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 hp


Thanks all for the links. let's see the variants.
First I need to decide should it be top-level namespace? my first
thought was yes, since I create a set of modules and  want to group it
under "one roof". And should it be descriptive name like CTX:: or
Multiple:: , Multi:: ; or can be like caption, brend name :) like
Loofort:: or some.
From the other hand it can be non top-level namespace. Maybe some
thing like NET::HTTP::Multy and NET::FTP::Multy. or this variant
Coro::Loofort:: or Coro::CTX::

It's hard to choose. currently I prefere the top-level namespace
Multy:: .
what you think?


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3280
***************************************


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