Re: Replacing the first line of a text file

2014-02-05 Thread Nathan Hilterbrand
See below the quoted text On 02/03/2014 08:12 PM, SSC_perl wrote: I'm having a problem with the script below. I want to alter just the first line of a CSV file, removing the prefix "tag_" from each value in that line. However, because the new line is shorter than the original, the sc

Re: Replacing the first line of a text file

2014-02-04 Thread SSC_perl
Thanks everyone. Both Tie::File and File::Slurp work nicely for this purpose. Now comes the hard part - picking which one I want to use. ;) Frank http://www.surfshopcart.com/ Setting up shop has never been easier! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additio

Re: Replacing the first line of a text file

2014-02-04 Thread Shawn H Corey
On Tue, 04 Feb 2014 11:59:30 + Rob Dixon 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 "ca

Re: Replacing the first line of a text file

2014-02-04 Thread Rob Dixon
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 fil

Re: Replacing the first line of a text file

2014-02-03 Thread Uri Guttman
On 02/03/2014 09:05 PM, Shawn H Corey wrote: On Mon, 03 Feb 2014 20:50:17 -0500 Uri Guttman wrote: Is there a way to replace the entire line with the new, shorter one? that is a unix problem and can't be done in any language. It's not even a UNIX problem. Windows and BSD have it too. It is

Re: Replacing the first line of a text file

2014-02-03 Thread Shawn H Corey
On Mon, 03 Feb 2014 20:50:17 -0500 Uri Guttman wrote: > > Is there a way to replace the entire line with the new, shorter > > one? > > that is a unix problem and can't be done in any language. It's not even a UNIX problem. Windows and BSD have it too. It is an artifact of how files are create

Re: Replacing the first line of a text file

2014-02-03 Thread Uri Guttman
On 02/03/2014 08:12 PM, SSC_perl wrote: I'm having a problem with the script below. I want to alter just the first line of a CSV file, removing the prefix "tag_" from each value in that line. However, because the new line is shorter than the original, the script is only over-writing part of the

Replacing the first line of a text file

2014-02-03 Thread SSC_perl
I'm having a problem with the script below. I want to alter just the first line of a CSV file, removing the prefix "tag_" from each value in that line. However, because the new line is shorter than the original, the script is only over-writing part of the original line (exactly the num