Leser: 3
![]() |
![]() |
10 Einträge, 1 Seite |
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 27
use File::Find; use strict; use warnings; my $dir = "path"; find(\&process, $dir); sub process { my $file = $_; my @newFile; open (FILE, "<$file"); while (my $line = <FILE>){ if ( $line =~ s/(print)\s*("\w+")/\$lang->$1($2, \$actUser->{'lang'})/g ){ print "\nFound: $1, $2\n"; } push @newFile, $line; } close FILE; open (FILE, ">$file"); foreach my $line (@newFile){ #print FILE $line; print $line; } close FILE; }
readline() on closed filehandle FILE at line 25.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
sub process { opendir(DIR, $dir) or die $!; (my $file) = grep { $_ !~ m/^\.{1,2}$/ } readdir(DIR); closedir(DIR) or die $!; my @newFile; open (FILE, "<$file") or die $!; while (my $line = <FILE>){ if ( $line =~ s/(print)\s*("\w+")/\$lang->$1($2, \$actUser->{'lang'})/g ){ print "\nFound: $1, $2\n"; } push @newFile, $line; } close FILE; open (FILE, ">$file"); foreach my $line (@newFile){ print FILE $line; #print $line; } close FILE; }
LanX-+2008-08-29 10:58:34--tsy+2008-08-29 10:49:57--
ist das wirklich beabsichtigt ?
renee+2008-08-29 11:21:35--@havi: Wenn Du das im Kontext des OP (mit File::Find) laufen lässt, wird für jeden Eintrag im Verzeichnisbaum die erste Datei von $dir genommen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
sub process { opendir(DIR, $dir) or die $!; my @file = grep { $_ !~ m/^\.{1,2}$/ } readdir(DIR); closedir(DIR); my @newFile; for (my $i = 0; $i <= $#file; $i++) { open (FILE, "<$file[$i]") or die $!; while (my $line = <FILE>){ if ( $line =~ s/(print)\s*("\w+")/\$lang->$1($2, \$actUser->{'lang'})/g ){ print "\nFound: $1, $2\n"; } push @newFile, $line; } close FILE; open (FILE, ">$file[$i]"); foreach my $line (@newFile){ print FILE $line; #print $line; } close FILE; } }
renee+2008-08-29 11:20:24--Warum nicht? File::Find setzt $_, so dass dort der Dateiname drinsteht. Man sollte nur noch auf Verzeichnis oder Datei prüfen (-d / -f)...
![]() |
![]() |
10 Einträge, 1 Seite |