Skip to content

Instantly share code, notes, and snippets.

Created September 28, 2016 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/40f78570806da2e8fd36d61090b4c1e7 to your computer and use it in GitHub Desktop.
Save anonymous/40f78570806da2e8fd36d61090b4c1e7 to your computer and use it in GitHub Desktop.
Replace_perl
#!/usr/bin/perl
use File::Find;
# Prepare folder paths
my @array_folder_path = ("./asc");
find(\&find_file_callback, @array_folder_path);
sub find_file_callback
{
unless (-d)
{
next if ($File::Find::name !~ /\.asc$/i);
my $data = read_file("$_");
$data =~ s/Have a wonderful day!/Good luck to you/g;
$data =~ s/ XX55/ YY66 /gi;
write_file("$_",$data);
print "$File::Find::name\n";
}
}
sub read_file {
my ($filename) = @_;
open my $in, '<:encoding(UTF-8)', $filename or die "Could not open '$filename' for reading $!";
local $/ = undef;
my $all = <$in>;
close $in;
return $all;
}
sub write_file {
my ($filename, $content) = @_;
open my $out, '>:encoding(UTF-8)', $filename or die "Could not open '$filename' for writing $!";;
print $out $content;
close $out;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment