Created
February 18, 2016 16:07
-
-
Save wh13371/7e71fb44376a6bfa2ac5 to your computer and use it in GitHub Desktop.
perl - flipflop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tiny "flip-flop" | |
use strict; | |
use warnings; | |
use 5.020; | |
use Getopt::Long qw(GetOptions); | |
Getopt::Long::Configure ("bundling"); # -lcd => line / chomp / debug | |
my $debug; | |
my $chomp; | |
my $line; | |
GetOptions('debug|d' => \$debug, 'chomp|c' => \$chomp, 'line|l' => \$line) or die "$0"; | |
#say $debug ? 'debug' : 'no debug'; | |
if ($debug) { if ( !@ARGV ) { say "USAGE: flipflop.pl <start_regex> <stop_regex> LOG"; exit 46; } } | |
if ($debug) { for ( @ARGV ) { say $_; } } | |
my $start_regex = shift; | |
my $stop_regex = shift; | |
while (<>) { | |
$_ =~ s/^\s*(.*?)\s*$/$1/ if $chomp; | |
if ( /$start_regex/ .. /$stop_regex/ ) # flip-flop | |
{ | |
if ($line) | |
{ | |
say $. . ":" . $_; # prefix line | |
} | |
else | |
{ | |
say $_; # no line | |
} | |
} | |
} | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment