[Israel.pm] using perl -pi but with s///s

Yossi.Itzkovich at ecitele.com Yossi.Itzkovich at ecitele.com
Mon Apr 11 02:13:29 PDT 2005






Without testing it I don't think it should work.
The code written is read after the file was open, and for each line.  It
will not help undeffing it after that.

Yossi



                                                                                                                                    
                      Levenglick                                                                                                    
                      Dov-RM07994              To:      "'Perl in Israel'" <perl at perl.org.il>                                       
                      <DovL at freescale.         cc:                                                                                  
                      com>                     Subject: RE: [Israel.pm] using perl -pi but with  s///s                              
                      Sent by:                                                                                                      
                      perl-bounces at per                                                                                              
                      l.org.il                                                                                                      
                                                                                                                                    
                                                                                                                                    
                      04/11/2005 11:55                                                                                              
                      Please respond                                                                                                
                      to Perl in                                                                                                    
                      Israel                                                                                                        
                                                                                                                                    
                                                                                                                                    



Perl -i -pe 'undef $/; s/this/that/g' file


Best Regards,
Dov Levenglick
The information contained in this email is classified as:
[ ] General Business Information
[ ] Freescale Internal Use Only
[ ] Freescale Confidential Propriety
[x] Personal Memorandum



-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
Of Gaal Yahas
Sent: Monday, April 11, 2005 9:27 AM
To: Perl in Israel
Subject: Re: [Israel.pm] using perl -pi but with s///s


On Mon, Apr 11, 2005 at 09:02:36AM +0300, Yossi.Itzkovich at ecitele.com
wrote:
> I want to substitute  in a file a multiline text:
> s/something/somewhat/gs
>
> How can I do it using perl -pi  ?  (perl -p reads line by line)

Use the -0 switch to specify a different input record separator. If your
data is text with paragraphs, and your pattern doesn't span paragraphs,
your best bet is to use the special -00 mode.

If not, you'll need to find something else that isn't in your pattern
and that hopefully still occurs regularly enough so that you don't have
to read huge chunks into memory at once.

If your file is small, all this doesn't matter much. Use slurp mode
(-0777).

--
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://perl.org.il/mailman/listinfo/perl






More information about the Perl mailing list