in reply to Re: something about improving code...
in thread something about improving code...

To e more precise to the problem at hand ( i.e. the program given by the asker of the question was 'not printing' when a line containing 'start' or 'stop' was encoutered ):
my( $START, $STOP ) = qw( START STOP );
while ( <DATA> ) {
  if ( /$START/ .. /$STOP/ ) {
    print /(?:$START|$STOP)/ ?  "not printing\n" : "PRINTING\n";
  } else {
    print "not printing\n";
  }
}
__END__
Hello,
I like to START
something and
not STOP it
properly.


---
output:

not printing
not printing
PRINTING
not printing
not printing

Enjoy!
--
Casey
  • Comment on RE: Re: something about improving code...

Replies are listed 'Best First'.
RE: RE: Re: something about improving code...
by merlyn (Sage) on Jun 28, 2000 at 03:27 UTC
    Even that has a simpler plan:
    my ($START, $STOP) = qw(START STOP); while (<DATA>) { $where = /$START/../$STOP/; if ($where and $where > 1 and $where !~ /E0/) { print "PRINTING\n"; } else { print "not printing"; } } __END__

    -- Randal L. Schwartz, Perl hacker

      Even more terse:
      use strict; my ($START, $STOP) = qw(START STOP); while (<DATA>) { my $where = /$START/../$STOP/; print (($where and $where > 1 and $where !~ /E0/) ? "PRINTING\n" : " +not printing"); } __END__
      --Chris

      Updated: to use 'use strict;'. merlyns will work also with this. -w, however, makes both unhappy.
        I didn't know we were golfing... :-)
        my ($START, $STOP) = qw(START STOP); while (<DATA>) { print (($where = /$START/../$STOP/ and $where !~ /^1$|E/) ? "PRINTIN +G" : "not printing"; }

        -- Randal L. Schwartz, Perl hacker