[32514] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3779 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 17 14:09:18 2012

Date: Mon, 17 Sep 2012 11:09:04 -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           Mon, 17 Sep 2012     Volume: 11 Number: 3779

Today's topics:
    Re: Setting backreference inside of a string <jwcarlton@gmail.com>
    Re: Setting backreference inside of a string <jwkrahn@example.com>
    Re: warning about pipe-to-self opens <rweikusat@mssgmbh.com>
    Re: warning about pipe-to-self opens <kaz@kylheku.com>
    Re: warning about pipe-to-self opens <rweikusat@mssgmbh.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 16 Sep 2012 16:01:28 -0700 (PDT)
From: Jason C <jwcarlton@gmail.com>
Subject: Re: Setting backreference inside of a string
Message-Id: <06e00786-93ce-4038-9fc3-851d9754a0b5@googlegroups.com>

On Wednesday, September 12, 2012 9:33:03 AM UTC-4, Ben Morrow wrote:
> That, IMHO, is basically the right approach, but you don't want to use a
> fixed string like "<marker>" because it might appear in the source text.
> Instead, you want something like this:
> 
>     sub dosubst {
>         my ($repl, $one) = @_;
>         $repl =~ s/\$(?:\{1\}|1)/$one/g;
>         $repl;
>     }
> 
>     $text =~ s/$pattern/dosubst $replace, $1/gie;
> 
> This assumes the replacement only uses $1. If you want to use arbitrary
> captures, it gets a little more difficult, since perl doesn't provide an
> array-of-all-the-captures variable. You would need to pass $text, \@-
> and \@+ into dosubst, and pull the captures out as required.

Thanks to all of you for the help! I did eventually get it working correctly; Ben's reply made it click for me :-)

Here's the original regex I was using:

$text =~ s/(\b*)$pattern(er|in|ing|s|ed|y|\b)/$1$replace$+/gi; 

and here's the variation that is now working, using the /e modifier:

$text =~ s/(\b*)$pattern(er|in|ing|s|ed|y|\b)/dosubst($replace, $1, $2, $3)/egi;

sub dosubst {
  my ($repl, $one, $two, $three) = @_;

  $repl =~ s/\$(?:\{2\}|2)/$two/g;
  $repl = "$one" . $repl . "$three";

  return $repl;
}

Essentially, it's sending the uninterpreted '$2' in $pattern to dosubst(), replacing it with the interpreted $two, then returning the whole updated variable.

I hope this helps someone in the future with a similar problem.


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

Date: Sun, 16 Sep 2012 16:11:37 -0700
From: "John W. Krahn" <jwkrahn@example.com>
Subject: Re: Setting backreference inside of a string
Message-Id: <J0t5s.302$U54.258@newsfe01.iad>

Jason C wrote:
>
> Thanks to all of you for the help! I did eventually get it working correctly; Ben's reply made it click for me :-)
>
> Here's the original regex I was using:
>
> $text =~ s/(\b*)$pattern(er|in|ing|s|ed|y|\b)/$1$replace$+/gi;

You can't use a modifier on a zero-width pattern.  \b matches BETWEEN 
characters so there is no way it could be longer than zero.

The pattern 'ing' will never match because the pattern 'in' appears 
before it.



John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein


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

Date: Sun, 16 Sep 2012 20:51:16 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: warning about pipe-to-self opens
Message-Id: <87haqx926j.fsf@sapphire.mobileactivedefense.com>

Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Rainer Weikusat <rweikusat@mssgmbh.com>:
>> At least on perl 5.10.1, in contradiction to the documentation which
>> states
>> 
>> 	Use "defined($pid)" to determine whether the open was
>> 	successful.
>> 
>> when the implicit fork done by open($fh, '|-') or open($fh, '-|')
>> fails for another reason than EAGAIN, the Perl interpreter executes
>> Perl_croak with "Can't fork" as argument.

[...]

> Wow, that bit of code's been there a long time: since perl 3, 18 Oct
> 1989. It would probably be helpful if you sent a doc patch to p5p.

IMO, this behaviour should rather be changed than documented. Also, I
have been on USENET and various other places on the internet since
1998, ageing from 25 to 39 in the process, and it took me until last
year to grow a sufficiently thick skin and accumulate enough
self-confidence to participate reguarly in a Perl-related newsgroup
because (parts of) the 'Perl community' is (are) the most aggressively
hostile group of individuals I've so far encountered on this planet,
especially considering that I'm an entirely self-taught university
dropout and that the last attempt at doing so brought me into a situation
were I was 'generously' 'allowed to work' but paid so little money
that I was technically starving (I'm being completely serious),
because 'some people' pulled some strings in the background. I would
never consider sending anything to a Perl mailing list.


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

Date: Sun, 16 Sep 2012 20:08:38 +0000 (UTC)
From: Kaz Kylheku <kaz@kylheku.com>
Subject: Re: warning about pipe-to-self opens
Message-Id: <20120916124843.461@kylheku.com>

On 2012-09-16, Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
> IMO, this behaviour should rather be changed than documented. Also, I
> have been on USENET and various other places on the internet since
> 1998, ageing from 25 to 39 in the process, and it took me until last
> year to grow a sufficiently thick skin and accumulate enough
> self-confidence to participate reguarly in a Perl-related newsgroup
> because (parts of) the 'Perl community' is (are) the most aggressively
> hostile group of individuals I've so far encountered on this planet,

LOL! You're not exactly Dalai Lama yourself.


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

Date: Sun, 16 Sep 2012 22:27:03 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: warning about pipe-to-self opens
Message-Id: <874nmx8xqw.fsf@sapphire.mobileactivedefense.com>

Kaz Kylheku <kaz@kylheku.com> writes:
> On 2012-09-16, Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
>> IMO, this behaviour should rather be changed than documented. Also, I
>> have been on USENET and various other places on the internet since
>> 1998, ageing from 25 to 39 in the process, and it took me until last
>> year to grow a sufficiently thick skin and accumulate enough
>> self-confidence to participate reguarly in a Perl-related newsgroup
>> because (parts of) the 'Perl community' is (are) the most aggressively
>> hostile group of individuals I've so far encountered on this planet,
>
> LOL! You're not exactly Dalai Lama yourself.

Especially in earlier times, I imitated to much of this style for
personal reasons which really don't belong here. But generally, I
criticize opinions and not people, except insofar a general
mudslinging contest has already been started. I consider his to be a
defect, however.


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

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


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