It's not too clear just what kind of transformations you want to do, but the data looks like the fields are different enough to each take completely different treatment.
How about making an array of subroutines, each handling the transformations for the field with the corresponding index?
So long as you don't use code tags, I can't tell where your data lines end or guess what you might want to do to them.my @xforms = ( sub { $_[0] = $_[0] || 1; }, sub { # dummy, no transform $_[0]; }, sub {1}, sub { $_[0] =~ s/foo/bar/; $_[0]; }, sub {1}, sub {1}, sub {1}, sub {1}, ); while (<DATA>) { my @tmp = split ','; for (0 .. $#tmp) { $xforms[$_]->($tmp[$_]); } print join ',', @tmp; }
After Compline,
Zaxo
In reply to Re: how to so this string replacement elegantly
by Zaxo
in thread how to so this string replacement elegantly
by edwardt_tril
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |