Jim wrote:
> I can't believe I didn't find this through searching.
> While looping through a file,array,hash etc.. how can I start printing only
> after a certain expression matches. in other words how can I skip the lines
> in the data until an expression match.
> Thanks
>
> --
>
> # want to print lines from apple on down
>
> while ($line = <DATA>) {
> next until $line =~ /^banan/;
$line never changes, so this is an infinite loop.
> print $line;
> }
>
>
> __DATA__
> orange
> peach
> banana
> apple
> pear
> mango
>
>
>
Try:
#!/usr/bin/perl
use strict;
use warnings;
my $print_line = 0;
while( <DATA> ){
if( /banana/ ){
$print_line = 1;
}elsif( $print_line ){
print;
}
}
__DATA__
orange
peach
banana
apple
pear
mango
--
__END__
Just my 0.00000002 million dollars worth,
--- Shawn
"For the things we have to learn before we can do them, we learn by
doing them."
Aristotle
* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>