From 522812e9a597f205ffa581ccf00ba2779e4ffe99 Mon Sep 17 00:00:00 2001 From: Andreas Hrubak Date: Mon, 28 Oct 2024 22:44:38 +0100 Subject: [PATCH] fix and generalize --- user-tools/pcut | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/user-tools/pcut b/user-tools/pcut index 7ad4c66..dba4bb5 100755 --- a/user-tools/pcut +++ b/user-tools/pcut @@ -97,17 +97,15 @@ while(<>) { push @PrintFields, $Fields[$1-1]; } - elsif($fields =~ /^(\d+)-(\d+)$/) + else { - push @PrintFields, @Fields[($1-1)..($2-1)]; - } - elsif($fields =~ /^(\d+)-$/) - { - push @PrintFields, @Fields[($1-1)..$#Fields]; - } - if($fields =~ /^-(\d+)$/) - { - push @PrintFields, @Fields[1..($1-1)]; + my $from; + my $to; + if($fields =~ /^(\d+)-(\d+)$/) { ($from, $to) = ($1-1, $2-1); } + elsif($fields =~ /^(\d+)-$/) { ($from, $to) = ($1-1, $#Fields); } + elsif($fields =~ /^-(\d+)$/) { ($from, $to) = (0, $1-1); } + else { die 'SHOULD-NOT-REACHED'; } + push @PrintFields, @Fields[$from..$to]; } } print join($OptOutputDelimiter, @PrintFields); -- 2.11.4.GIT