[29686] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 930 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 12 11:09:47 2007

Date: Fri, 12 Oct 2007 08:09:10 -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           Fri, 12 Oct 2007     Volume: 11 Number: 930

Today's topics:
    Re: add 1 to the captured backreference ?? <peter@makholm.net>
    Re: add 1 to the captured backreference ?? <kenslaterpa@hotmail.com>
    Re: add 1 to the captured backreference ?? <jbl02NO@SPAMhotmail.com>
    Re: add 1 to the captured backreference ?? <mgjv@tradingpost.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 12 Oct 2007 10:12:46 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: add 1 to the captured backreference ??
Message-Id: <871wc0tzdt.fsf@hacking.dk>

jbl <jbl02NO@SPAMhotmail.com> writes:

> use warnings;
> use strict;
> while (<DATA>)
> {
> 	my $string = $_;
> 	$string =~ s/(\d)/$1+1/g;
> 	print $string;
> }

You have to use the /e flag to you substitution the get the right side
of the substitution evaluated as a perl expression.

//Makholm


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

Date: Fri, 12 Oct 2007 03:12:59 -0700
From:  kens <kenslaterpa@hotmail.com>
Subject: Re: add 1 to the captured backreference ??
Message-Id: <1192183979.805111.187060@k35g2000prh.googlegroups.com>

On Oct 12, 5:50 am, jbl <jbl0...@SPAMhotmail.com> wrote:
> It seems like it shoukd be simple but it it driving me more crazy than
> I already was.
>
> All I want to do is add 1 to each and any number in the string.
> ie... 1 becomes 2
> All I am doingwith this is putting a literal '+1'
>
> # changeNumbers.pl
> # desired output
> # string text 2 string text
> # string text 2 string text 3 string text
> # string text 2 string text 3 4 string text 5 6 string text
>
> use warnings;
> use strict;
> while (<DATA>)
> {
>         my $string = $_;
>         $string =~ s/(\d)/$1+1/g;
>         print $string;}
>
> __DATA__
> string text 1 string text
> string text 1 string text 2 string text
> string text 1 string text 2 3 string text 4 5 string text
>
> this is my actual output;
>
> C:\>changeNumbers.pl
> string text 1+1 string text
> string text 1+1 string text 2+1 string text
> string text 1+1 string text 2+1 3+1 string text 4+1 5+1 string text
>
> thanks,
>
> jbl

Close, change the following line
   $string =~ s/(\d)/$1+1/g;
to
   $string =~ s/(\d)/($1+1)/eg;

HTH, Ken



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

Date: Fri, 12 Oct 2007 05:41:38 -0500
From: jbl <jbl02NO@SPAMhotmail.com>
Subject: Re: add 1 to the captured backreference ??
Message-Id: <1mjug3h4mecpgjbcvndt4qcpsm0u5jv7a1@4ax.com>

On Fri, 12 Oct 2007 10:12:46 +0000, Peter Makholm <peter@makholm.net>
wrote:

>jbl <jbl02NO@SPAMhotmail.com> writes:
>
>> use warnings;
>> use strict;
>> while (<DATA>)
>> {
>> 	my $string = $_;
>> 	$string =~ s/(\d)/$1+1/g;
>> 	print $string;
>> }
>
>You have to use the /e flag to you substitution the get the right side
>of the substitution evaluated as a perl expression.
>
>//Makholm

Thanks, now it works. Sometimes I cannot see the forest with all of
those trees in the way.
jbl


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

Date: Fri, 12 Oct 2007 20:29:28 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: add 1 to the captured backreference ??
Message-Id: <slrnfguj48.sha.mgjv@martien.heliotrope.home>

On Fri, 12 Oct 2007 04:50:30 -0500,
	jbl <jbl02NO@SPAMhotmail.com> wrote:
> It seems like it shoukd be simple but it it driving me more crazy than
> I already was.
>
> All I want to do is add 1 to each and any number in the string.
> ie... 1 becomes 2
> All I am doingwith this is putting a literal '+1'

> 	$string =~ s/(\d)/$1+1/g;

$string =~ s/(\d)/$1+1/ge;

I would probably do

$string =~ s/(\d+)/$1+1/ge;

depending on whether you want an embedded 14 to increment to 25 or 15,
and 19 to 210 or 20.

The perlop documentation explains what the e modifier does for s///.

Martien
-- 
                        | 
Martien Verbruggen      | +++ Out of Cheese Error +++ Reinstall
                        | Universe and Reboot +++
                        | 


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 930
**************************************


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