in reply to need a regular exdpression in perl

ok, my program looks as below

#!/usr/bin/perl use strict; use File::Find; use warnings; my @file=("hh","yy","zz","aa","bb","hh","yy","zz","aa","bb","hh","yy", +"zz","aa","bb"); my $i=0; $string=" hi hello @begintobe replace @end asas x x x x x zxzxax hi hello hi hellooo @beginthis has tobe replaced @end"; my $x=$file[$i]; while ($string =~ s/\@begin([\w\W]*?)\@end/$x/ge) { $i++; $x=$file[$i]; print $i."\n"; } print $string;

and i am getting output as below so far<\p>

##output hi hello hh asas x x x x x zxzxax hi hello hi hellooo hh

only the first element in the arrray is getting replaced in every match...

Replies are listed 'Best First'.
Re^2: need a regular exdpression in perl
by Eily (Monsignor) on Nov 20, 2014 at 09:38 UTC

    This does not even compile, and even if it did, $string does not contain either @begin or @end (try printing it without doing any replacement). Have a look at Loops's post on that point.

    If strict gives you errors (when you actually use it, and don't just put it when you update your code on perlmonks), it's nearly always a sign that the code is wrong, and doesn't mean what you expect. Same goes for warnings.