karmas has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use warnings; use strict; use File::Find; my $base = "C:\\Projects\\test"; my $ext = qr/.cpp$/; my $regexp = qr/throw "(.+)"/; my $substitute = qq{throw \("$1"\)}; find(\&process, $base); # Collect files matching pre-set extension sub process { /$ext/ or return; my ($line, $file); $file = $File::Find::name; $file =~ s{/}{\\}g; open (IN, '<', $file) or die "Can not open $file: $!"; while (defined($line = <IN>)) { next if $line !~ /$regexp/; chomp $line; print "$file:\n\t$line\n"; $line =~ s/$regexp/$substitute/; print "\t$line\n"; } close(IN); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Execute regexp on directory tree
by Hofmator (Curate) on Dec 12, 2001 at 14:16 UTC | |
by karmas (Sexton) on Dec 12, 2001 at 16:02 UTC | |
|
Re: Execute regexp on directory tree
by Anarion (Hermit) on Dec 12, 2001 at 14:41 UTC |