Thread File::Find und move
(14 answers)
Opened by Gast at 2010-02-09 17:58
Ist in diesem Kontext die "-e $file"-Abfrage überflüssig?
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 #!/usr/bin/env perl use warnings; use strict; use File::Copy; use File::Find; my $dir = '/home/oo/bin'; find( \&wanted, $dir ); sub wanted { my $file = $File::Find::name; if ( -e $file and -f $file ) { my $temp = 'temp_file'; open my $out, '>', $temp or die $!; open my $in, '<', $file or die $!; while ( defined( my $row = <$in> ) ) { $row =~ s|^#!/usr/bin/perl|#!/usr/bin/env perl|; print $out $row; } close $in or die $!; close $out or die $!; move $temp, $file or die $!; chmod 0755, $file or die $!; } } |