On 10/02/2013 08:44 PM, Peter Holsberg wrote:
Uri Guttman has written on 10/2/2013 8:39 PM:

        use File::Slurp qw( read_dir edit_file ) ;

        foreach my $file ( grep /^\d{6}\.htm$/, read_dir( $dir ) ) {

                edit_file { s/foo/bar/g } $file ;
        }

read_dir is also from File::Slurp and reads a whole dir for you. no need
for glob or opendir.

the code block in edit_file can be changed to call a sub to do a more
complex edit. it sets $_ to the entire file content.

Thank you, Uri.

Two questions:

1) As there will be only one instance of the file each time I run the
script, do I need the loop?

for now you still need the loop. i was thinking of adding multiple file argument support to edit_file. i will put it in a todo list.


2) Does edit_file change the file in place or write it to STDOUT?

good question. read the docs and see what they say. this is a good thing to learn even for an old dog! :)

thanx

uri

--
Uri Guttman - The Perl Hunter
The Best Perl Jobs, The Best Perl Hackers
http://PerlHunter.com

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to