in reply to newbie regex question: substituting repeating occurences for different replacements
That works. Not the prettiest thing in the world though.my $row = "hello;this;is;a;test"; my $i = 1; print "row: $row\n"; $row =~ s/;/"<\/col". $i++ ."><col$i>"/eg; $row = "<col1>" . $row . "<col$i>"; print "row: $row\n";
Notice that these all deal with just a single line though easily expanded to cover multiple lines.my $row = "hello;this;is;a;test"; my $i = 1; print "row: $row\n"; @cols = split(/;/,$row); foreach $col (@cols) { $output .= "<col$i>$col</col$i>"; $i++} print "row: $output\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: newbie regex question: substituting repeating occurences for different replacements
by Aristotle (Chancellor) on Jul 21, 2003 at 19:02 UTC | |
by eric256 (Parson) on Jul 23, 2003 at 17:56 UTC | |
by Aristotle (Chancellor) on Jul 23, 2003 at 19:05 UTC |