On May 15, 7:13 pm, u...@stemsystems.com ("Uri Guttman") wrote:
> >>>>> "PJ" == Paul Johnson <p...@pjcj.net> writes:
>
>   PJ> On Sun, May 15, 2011 at 01:31:47PM -0400, Jim Green wrote:
>   >> this is very nice, don't need to call perl in perl anymore..
>   >>
>   >> perl -pi -e '$_ = "" if /foo/' filename
>   >>
>   >> but what if the file is very large? slurping the file in to memory will
>   >> be ok?
>   >>
>   >> or is there any other alternatives you are aware of? or you can dismiss?
>
>   PJ> {
>   PJ>     local ($^I, @ARGV) = ("", "filename");
>   PJ>     while (<>)
>   PJ>     {
>   PJ>         print unless /foo/;
>   PJ>     }
>   PJ> }
>
>   PJ> is the idiomatic way to do that.  Well, to do:
>
> and also very slow and also clunky. as i said, you need to localize
> those vars and also not be using <> elsewhere. it is just a bad idiom
> and now it can be laid to rest. :)
>
>   PJ>   perl -ni -e 'print unless /foo/' filename
>
> about the same as my version. i wanted to show how you would do the same
> logic with both -pi and edit_file_lines. my sub doesn't have a print
> command so you can invert the logic which is why i used -p and not -n.
>
>   PJ> which is the idiomatic way to do what you had written.  For a more
>   PJ> direct translation, substitute the loop contents with
>
>   PJ>         $_ = "" if /foo/;
>   PJ>         print;
>
> and you don't need the print if you use -p.

Is there a preferred way to append a text file to the end of gzipped
file? the api of File::Slurp append_file is nice, but doesn't work
with gzip file...

Thanks!

>
> uri
>
> --
> 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/


Reply via email to