On Tue, 04 Feb 2014 11:59:30 +0000
Rob Dixon <rob.di...@gmx.com> wrote:

> If it is satisfactory to leave the original file with trailing spaces
> at the end of the first line, then you can do so like this
> 
> use strict;
> use warnings;
> 
> my $filename = 'products.csv';
> open (my $fh, '+<', $filename) || die "can't open $filename: $!";
> 
> chomp(my $line = <$fh>);
> (my $new_line = $line) =~ s/tag_//gi;
> my $pad_size = length($line) - length($new_line);
> 
> seek $fh, 0, 0;
> printf {$fh} $line, ' ' x $pad_size;

    printf {$fh} $new_line, ' ' x $pad_size, "\n";

> 
> close $fh or die $!;



-- 
Don't stop where the ink does.
        Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to