in reply to replace nth occurrence of |
use warnings; use strict; while (my $row = <DATA>) { my $pos1 = 10; $row =~ s/(\|)/!--$pos1 ? ' pipe ' : $1/ge; my $pos2 = 10; $row =~ s/(\|)/!--$pos2 ? ' pipe ' : $1/ge; my $pos3 = 10; $row =~ s/(\|)/!--$pos3 ? ' pipe ' : $1/ge; chomp $row; print "$row\n"; } print "doneagain\n"; __DATA__ 1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i
Outputs:
1|2|3|4|5|6|7|8|9|a pipe b pipe c pipe d|e|f|g|h|i doneagain
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: replace nth occurrence of |
by perl197 (Novice) on Sep 24, 2014 at 17:29 UTC |