in reply to Re: Split files based on regexp
in thread Split files based on regexp

druthb:

You may want to experiment with the flip/flop operator "..". It basically does the work of your $in_combat logic. It takes a little while to get used to, but it certainly makes the code a bit simpler once you're used to it:

$ cat krunk.pl #!/usr/bin/perl # # Demo for flip-flop operator # use 5.14.0; use warnings; use autodie; while (<DATA>) { if (/start/ .. /stop/) { # in combat! print "COMBAT: $_"; } } __DATA__ soon the combat will begin start combat! Biff! Pow! Bam! (Looks like Batman!) stop combat fight had three superlatives $ perl krunk.pl COMBAT: start combat! COMBAT: Biff! Pow! Bam! COMBAT: (Looks like Batman!) COMBAT: stop combat

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^3: Split files based on regexp
by druthb (Beadle) on May 17, 2012 at 12:43 UTC

    Brilliant! I had not seen that operator before. Thanks oodles, roboticus!

    D Ruth Bavousett