Created
September 28, 2016 15:03
-
-
Save anonymous/40f78570806da2e8fd36d61090b4c1e7 to your computer and use it in GitHub Desktop.
Replace_perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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