From 0526102864aaad148711715ad4e7d22c1de89263 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 3 Oct 2011 22:04:20 +0200 Subject: regcheck.pl: rework to print only matches Signed-off-by: Florian Pritz --- regcheck.pl | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'regcheck.pl') diff --git a/regcheck.pl b/regcheck.pl index c5a7023..c5b5f89 100755 --- a/regcheck.pl +++ b/regcheck.pl @@ -3,18 +3,25 @@ use warnings; use strict; use File::Basename; -if (@ARGV != 2) { +if (@ARGV < 2) { print "usage: ", basename($0), " \n"; exit 2; } -my $string = $ARGV[1]; -my $pattern = $ARGV[0]; +my $pattern = shift; -if ($string =~ /$pattern/) { - print "\e[0;32mmatches:\e[0m $&\n"; - exit 0; -} else { - print "\e[0;31mno match\e[0m\n"; - exit 1; +for my $string (@ARGV) { + if (my @matches = $string =~ /$pattern/) { + print "\e[0;32mmatches:\e[0m "; + if ($#- != 0) { + for my $match (@matches) { + print $match; + } + } else { + print "$&"; + } + print "\n"; + } else { + print "\e[0;31mno match\e[0m\n"; + } } -- cgit v1.2.3-24-g4f1b