in reply to something about improving code...

You have something against this simpler code?
$START = 'START'; $END = 'END'; while (<>) { if (/$START/../$END/) { print "inside\n"; } else { print "outside\n"; } }
This seems much simpler. Don't reinvent the scalar dot-dot operator!

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: Re: something about improving code...
by cwest (Friar) on Jun 28, 2000 at 01:54 UTC
    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
    
      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.