MDK-Common

 view release on metacpan or  search on metacpan

lib/MDK/Common/File.pm  view on Meta::CPAN



sub substInFile(&@) {
    my ($f, $file) = @_;
    #FIXME we should follow symlinks, and fail in case of loop
    if (-l $file) {
        my $targetfile = readlink $file;
        $file = $targetfile;
    }
    if (-s $file) {
	local @ARGV = $file;
	local $^I = '.bak';
	local $_;
	while (<>) { 
	    $_ .= "\n" if eof && !/\n/;
	    &$f($_); 
	    print;
	}
	open(my $F, $file);
	fsync($F);
	unlink "$file$^I"; # remove old backup now that we have closed new file

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.801 second using v1.00-cache-2.02-grep-82fe00e-cpan-c9a218a2bbc )