Re: Regex help?

[email protected] ("Dr.Ruud")
Newsgroups perl.beginners
Organization Chaos rules.
Message-ID <[email protected]>
"sanket vaidya" schreef:

> use warnings;
> use strict;
> my $i=1;
> while($i<=10)
> {
>     $_ = "abcpqr";
>     $_=~ s/(?=pqr)/$i/;
>     print "$_\n";
>     $i++;
> }
> [...]
> 
> The expected output is
> abc001pqr
> [...]
> Can any one suggest me how to get that output using regex. i.e. Can
> this happen by making change in regex I used in code??

Why use a regular expression, or even a substitution? 

perl -Mstrict -Mwarnings -e'
    printf q{abc%03dpqr%s}, $_, $/ for 1..3;
'
abc001pqr
abc002pqr
abc003pqr

-- 
Affijn, Ruud

"Gewoon is een tijger."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.