On 04/02/2014 01:12, SSC_perl wrote:
use strict;
use warnings;

my $filename = 'products.csv';
open (my $fh, '+<', $filename) || die "can't open $filename: $!";
my $line = <$fh>;
$line =~ s/tag_//gi;
seek $fh, 0, 0;
printf {$fh} $line;
close $fh;


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;

close $fh or die $!;


or much more simply you could use the Tie::File module, like this

use strict;
use warnings;

use Tie::File;

my $filename = 'products.csv';

tie my @file, 'Tie::File', $filename or die "can't open $filename: $!";
$file[0] =~ s/tag_//gi;
untie @file;


HTH,

Rob


---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com


--
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