On Sunday 11 July 2004 14:12, Paul Smith wrote:
>
> John W.Krahn wrote:
> >
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
> >
> > ( $^I, @ARGV ) = ( '.bak', 'text_file' );
> > while ( <> ) {
> > s/^#// if /Zyloric/;
> > print;
> > }
>
b> Thanks, John and Gunnar. (Please, be patient with my ignorance.) How
> can one refer, inside the loop while, to the next line in the text
> file? To be more precise, I would like to remove the character # in
> the next line to the one containing "Zyloric". I could use an
> auxiliary variable, but is there some easier way?
#!/usr/bin/perl
use warnings;
use strict;
( $^I, @ARGV ) = ( '.bak', 'text_file' );
while ( <> ) {
if ( /Zyloric/ ) {
print;
( $_ = <> ) =~ s/^#//;
}
print;
}
__END__
Or as a one-liner:
perl -i.bak -pe'/Zyloric/&&print&&($_=<>)=~s/^#//' text_file
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>