in reply to read and write to same file

#! /usr/bin/perl use strict; use warnings; use Tie::File; my $file = '/path/to/file.ext'; tie my @array,'Tie::File',$file or die $!; $_ =~ s/,$/ / for(@array); untie @array;
see Tie::File

Replies are listed 'Best First'.
Re^2: read and write to same file
by xdg (Monsignor) on Aug 19, 2005 at 10:53 UTC

    For this, a one-liner works, too:

    $ perl -p -i -e 's/,$/ /' somefile.txt

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^2: read and write to same file
by Anonymous Monk on Aug 19, 2005 at 10:52 UTC
    thanks for that, another new module to add to the list