in reply to string replacement question
A position-based string can easily take substitutions using substr. Since you presumably know the positions and widths, you can say:
while (<$ifh>) { substr($_, $position, $width) =~ s/foo/bar/; print $ofh $_; # update $position and $width if necessary }
Another approach is to unpack into an array or list of variables, make the modifications on those, and then pack back into a line to be printed to the output file.
Also, you can read a fixed-length chunk by setting local $/ = \42; (or whatever the record length is). That can be used to skip headers before the rest of the file is processed, too.
Update: Looking at the now-formatted data, I think I may have misunderstood what you meant by "position". Is this a CSV file? If so, follow that link.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: string replacement question
by edwardt_tril (Sexton) on Nov 30, 2005 at 07:17 UTC | |
by Zaxo (Archbishop) on Nov 30, 2005 at 07:28 UTC |