File::Searcher::Interactive -- Searches for files and performs search/replacements on matching files, uses terminal to make the searches interactive.
use File::Searcher::Interactive; my $search = File::Searcher->new('*.cgi'); $search->add_expression(name=>'street', search=>'1234 Easy St.', replace=>'456 Hard Way', options=>'i'); $search->add_expression(name=>'department', search=>'(Dept\.|Department)(\s+)(\d+)', replace=>'$1$2$3', options=>'im'); $search->add_expression(name=>'place', search=>'Portland, OR(.*?)97212', replace=>'Vicksburg, MI${1}49097', options=>'is'); $search->interactive; # $search->start; SEE File::Searcher @files_matched = $search->files_matched; print "Files Matched\n"; print "\t" . join("\n\t", @files_matched) . "\n"; print "Total Files:\t" . $search->file_cnt . "\n"; print "Directories:\t" . $search->dir_cnt . "\n"; my @files_replaced = $search->expression('street')->files_replaced;my @files_replaced = $search->expression($expression)->files_replaced; my %matches = $search->expression('street')->matches; my %replacements = $search->expression('street')->replacements;
File::Searcher::Interactive is a sub-class of File::Searcher which allows for the traversing of a directory tree for files matching a Perl regular expression. When a match is found, the statistics are stored and if the file is a text file a series of searches and replacements can be performed. File::Searcher::Interactive uses the terminal to prompt the user for interactive replacements.
File::Searcher::Interactive
File::Searcher
/path/to/file.txt
some pre text is here...
the current match is bold
and some post text is here...
--------------
current replace(.*?)expression
[Y]Replace [A]All In File [Z]All Files [P]Preview [M]More [default Next]
[Y]Replace - Replaces current match, with current replace expression
[A]All In File - Replaces all matches for this expression in this file
[Z]All Files - Replaces all matches for this expression in all files
[P]Preview - Preview the change, before deciding to proceed
[M]More - Show more pre-text and post-text
Be sure to test on your terminal before "guaranteed" reliability
Super complex regular expressions probably won't work the way you think they will.
Let me know...
More advanced functionality
More reporting (line numbers, etc.)
Find Term::Prompt fix
File::Searcher, Term::ANSIColor, Term::Prompt
Copyright 2000, Adam Stubbs
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Please email me if you find this module useful.
Adam Stubbs, astubbs@advantagecommunication.com (mailto:astubbs@advantagecommunication.com)
astubbs@advantagecommunication.com (mailto:astubbs@advantagecommunication.com)
Version 0.9, Last Updated November 14, 2000
To install File::Searcher::Interactive, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Searcher::Interactive
CPAN shell
perl -MCPAN -e shell install File::Searcher::Interactive
For more information on module installation, please visit the detailed CPAN module installation guide.