in reply to Substitute Question
Prints:use strict; use warnings; my $start_tag = qr/\*\*\* begin file \*\*\*/; my $end_tag = qr/\*\*\* end file \*\*\*/; my $case = ''; while ( <DATA> ) { # The range operator is sorely underused. if ( /$start_tag/ .. /$end_tag/ ) { if ( /$start_tag/ or /$end_tag/ ) { s/file/substituted file/; } else { $case = $_ & ' ' x length; s/old/NEW/i; } print $_ | $case; } } __DATA__ test *** begin file *** old_word OLD_WORD oLd_wOrd olD_worD *** end file *** test2
*** begin substituted file *** new_word NEW_WORD nEw_wOrd neW_worD *** end substituted file ***
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Ovid - coming in late) Re: Substitute Question
by merlyn (Sage) on May 30, 2001 at 02:31 UTC | |
by Ovid (Cardinal) on May 30, 2001 at 02:40 UTC | |
by merlyn (Sage) on May 30, 2001 at 03:51 UTC |