in reply to Cleaning Data Between Specified Columns

You could do something like the following:
substr($line, $pos1, $pos2) = cleanse(substr($line, $pos1, $pos2));
You would have to work from the high indicies to the low ones in order to avoid messing up your offset counts.

Replies are listed 'Best First'.
Re: Re: Cleaning Data Between Specified Columns
by tall_man (Parson) on Jan 27, 2003 at 19:29 UTC
    The third parameter should be a length, not a position.
    substr($line, $pos1, $pos2-$pos1+1) = cleanse(substr($line, $pos1, $po +s2-$pos1+1));
    Update:Here is some sample code, simplified in its input and output. The "local *tmp" trick by Fletch would also work, but I found it wouldn't pass strict without a "use vars qw($tmp);", so I went back to the simpler temporary variable idea.
    use strict; my @pos = (0,5,15,20); while(my $line = <>) { my $i = $#pos; while ($i >= 1) { my $pos1 = $pos[$i - 1]; my $pos2 = $pos[$i]; my $len = $pos2 - $pos1 + 1; my $part = substr( $line, $pos1, $len ); $part =~ y/'//d; $part =~ y/a-zA-Z0-9\n\|-/ /c; substr( $line, $pos1, $len ) = $part; $i -= 2; } # end while $i print $line; } # end while