braveghost has asked for the wisdom of the Perl Monks concerning the following question:
or with help of recursion function, but i want try to do it using executable regexp with g option (instead of while).my $data = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,".('c'x50).",16,17,1 +8,19,20,21,22,23,24,25,26,27"; while ($data =~/[^\n]{16}/) { $data =~s/([^\n]{16})/ch($1)/e; } print $data; sub ch { my $s = shift; my $p = rindex($s, ',', 14)+1; $p=15 unless($p); return substr($s, 0, $p)."\n".substr($s, $p) };
but in with case result is wrong, because tail of previous result concatinates with head of new. To escape with situation we must to change current search position in regexp to earlier value (even if we set 0 it's ok). Pos() function allow to change search position in regexp, but it seems it can't be use inside of regexp itself.$data =~s/([^\n]{16})/ch($1)/ge;
So my question is: Is it possible change search position from regexp itself?$data =~s/([^\n]{16})/pos($data)=0;ch($1)/ge;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using pos() inside regexp (no /e)
by tye (Sage) on Oct 08, 2010 at 05:37 UTC | |
by braveghost (Acolyte) on Oct 08, 2010 at 10:45 UTC | |
by ikegami (Patriarch) on Oct 08, 2010 at 15:32 UTC | |
by tye (Sage) on Oct 08, 2010 at 17:48 UTC | |
by braveghost (Acolyte) on Oct 09, 2010 at 07:28 UTC | |
by andal (Hermit) on Oct 08, 2010 at 15:32 UTC | |
by ikegami (Patriarch) on Oct 08, 2010 at 15:38 UTC | |
by Anonymous Monk on Oct 12, 2010 at 08:05 UTC | |
| |
by braveghost (Acolyte) on Oct 08, 2010 at 22:44 UTC | |
by ww (Archbishop) on Oct 09, 2010 at 00:54 UTC | |
|