Uri Guttman has written on 10/2/2013 8:39 PM: > On 10/02/2013 08:02 PM, Peter Holsberg wrote: >> <sigh> Let me start over. >> >> The file I want to modify has a 6-digit filename and an extension htm. >> For example, 131002.htm > > i figured that was the case. you should state that in the beginning and > then say a regex to match that is \d{6}\.htm. then you can use the regex > in a grep or in a loop or other ways. >> >> I'm working in Windows, with Strawberry perl, with Randall L. Schwartz's >> "Learning Perl", copyright 1993. I also have "Perl 5 Pocket Reference", >> 1998 and copies of "Programming Perl" and "Perl Cookbook", all last >> century. That's how current my knowledge is. :-) > > for what you are trying to do, that is fine. nothing is so new in perl > that will make this simple project any simpler. > > i do recommend you try to use File::Slurp to read in and write out your > files. it even has a edit_file sub which can do the i/o and editing in > one call. i didn't keep your edit request so i can't show you how to use > it that way. this is one way to do it: > > 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? 2) Does edit_file change the file in place or write it to STDOUT? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/