On May 15, 1:28 am, u...@stemsystems.com ("Uri Guttman") wrote: > hi all, > > As with other releases of File::Slurp I think this list should be told > about it since this module is so easy to use and makes your Perl much > simpler and also faster. > > uri > > Have you ever wanted to use perl -pi inside perl? did you have the guts > to localize $^I and @ARGV to do that? now you can do that with a simple > call toedit_fileor edit_file_lines in the new .018 release of > File::Slurp. Now you can modify a file in place with a simple call. > > edit_filereads a whole file into $_, calls its code block argument and > writes $_ back out the file. These groups are equivalent operations: > > perl -0777 -pi -e 's/foo/bar/g' filename > > use File::Slurp qw(edit_file) ; > > edit_file{ s/foo/bar/g } 'filename' ; > > edit_filesub { s/foo/bar/g }, 'filename' ; > > edit_file\&replace_foo, 'filename' ; > sub replace_foo { s/foo/bar/g } > > edit_file_lines reads a whole file and puts each line into $_, calls its > code block argument and writes each $_ back out the file. These groups are > equivalent operations: > > perl -pi -e '$_ = "" if /foo/' filename > > use File::Slurp qw( edit_file_lines ) ; > > edit_file_lines { $_ = '' if /foo/ } 'filename' ; > > edit_file_lines sub { $_ = '' if /foo/ }, 'filename' ; > > edit_file\&delete_foo, 'filename' ; > sub delete_foo { $_ = '' if /foo/ } > > So now when someone asks for a simple way to modify a file from inside > Perl, you have an easy answer to give them.
I tried my @texts = read_file( 'zcat filename.gz|' ) but it doesn't work, could someone help with this syntax? I would use PerlIO::gz for large files but prefer a simple call to get the content I want for smaller files. Thanks! Jim. > > -- > Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com-- > ----- Perl Code Review , Architecture, Development, Training, Support ------ > --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com--------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/