in reply to Re: Re: Search & Replace in subdirectory files
in thread Search & Replace in subdirectory files

I can not see, how you lose a line, that is a error somewhere else. To replace '$Log:' with '$History:' this is enough.
$input =~ s/\$Log:/\$History:/gi;
Note that $InputArray is _not_ a array.
Boris

Replies are listed 'Best First'.
Re: Search & Replace in subdirectory files
by Rina (Initiate) on Apr 23, 2004 at 17:00 UTC
    "perl -p -i.bak -e 's/\$Log/\$History/gi' * " at the command line only creates filename.ext.bak, nothing else.

    Boris, you're right, but I only showed a snippet of my code. I had something else being sent to the output file instead of $InputArray.

    Below is the full script, which works on a single file. Actually, I don't want to create a new file, I just want to modify the existing file, but this is what I know to do so far. I'm thinking there's a way to use "readdir" to provide the list of files so that the first line would read something like " Open (InputFile, $FileArray)".

    Thanks a LOT!!!



    open( InputFile, "FirstFile.txt" );
    open( OutputFile, ">SecondFile.txt" );
    @InputArrays = <InputFile>;

    foreach $InputArray ( @InputArrays)
    {
    $InputArray =~ s/\$Log/\$History/gi;
    chomp ($InputArray);
    @myColumns = split(/\\/, $InputArray);
    print (OutputFile "\n$InputArray");
    }

    close( InputFile );
    close( OutputFile );
      perl -p -i.bak -e 's/\$Log/\$History/gi' *
      Creates backupfiles with the extension .ext and modifies the original files where all occurances of $Log are replaced with $History. This is done for every file in this case since you choice *.
      $InputArray is a scalar not an Array.
      To replace any occurance of $Log to $History: try this but on a backup please. the first argument is the dir where the files life.
      #!/usr/bin/perl use File::Find; my @dirs = @ARGV; @ARGV = (); File::Find::find( { wanted => sub { push @ARGV, $File::Find::name if -f } }, @dirs ); local $^I; while ( defined( $_ = <ARGV> ) ) { s/\$Log:/\$History:/gi; print; }
      Boris