0 Replies - 1245 Views - Last Post: 22 May 2009 - 03:02 PM

#1 chorny_cpan   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 13-May 09

Replace all entries

Posted 22 May 2009 - 03:02 PM

Description: Requires File::Slurp to be installedReplace all entries in files specified in command line Works with Unix wildcards even on Windows
#!/usr/bin/perl

#Replace all entries in files specified in command line
#Works with Unix wildcards even on Windows
#Requires File::Slurp to be installed

use strict;
use warnings;
use File::Glob ':glob';
use File::Slurp;
foreach my $dir (@ARGV) {
  my @filelist = bsd_glob($dir);
  foreach my $file (@filelist) {
    next if -d $file;
    my $c=read_file($file);
    if ($c=~s/Find/Replace/g) {
      print "replaced in $filen";
      write_file($file,$c);
    } else {
      print "no match in $filen";
    }
  }
}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1