I
ioneabu
open $file, '+>', $File::Find::name;
This did not do what I expected. It deleted all my file's contents!
Here's my whole program:
#!/c:/perl/bin/perl.exe
#change shebang line for my Windows computer for all scripts
use warnings;
use strict;
my $shebang = '#!/c:/perl/bin/perl.exe';
use File::Find;
find(\&wanted, $ARGV[0]);
sub wanted
{
if (/\.pl$/)
{
open my $file, '<', $File::Find::name;
my $contents = <$file>;
close $file;
return if not $contents;
chomp $contents;
return if $contents =~/^$shebang$/;
if ($contents =~/^#!/)
{
open $file, '<', $File::Find::name;
my @contents = <$file>;
close $file;
$contents[0] = $shebang."\n";
open $file, '>', $File::Find::name;
print $file @contents;
close $file;
print "Changed: $File::Find::name\n";
}
}
}
Did I really have to open and close so many times? Thanks!
wana
This did not do what I expected. It deleted all my file's contents!
Here's my whole program:
#!/c:/perl/bin/perl.exe
#change shebang line for my Windows computer for all scripts
use warnings;
use strict;
my $shebang = '#!/c:/perl/bin/perl.exe';
use File::Find;
find(\&wanted, $ARGV[0]);
sub wanted
{
if (/\.pl$/)
{
open my $file, '<', $File::Find::name;
my $contents = <$file>;
close $file;
return if not $contents;
chomp $contents;
return if $contents =~/^$shebang$/;
if ($contents =~/^#!/)
{
open $file, '<', $File::Find::name;
my @contents = <$file>;
close $file;
$contents[0] = $shebang."\n";
open $file, '>', $File::Find::name;
print $file @contents;
close $file;
print "Changed: $File::Find::name\n";
}
}
}
Did I really have to open and close so many times? Thanks!
wana