From 4855cd33928ac5c3003ad747048a7e5d5477bff8 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 31 Oct 2022 20:53:24 +0100 Subject: [PATCH] empty program arguments do not need to be parsed Using Getopt::Long takes ~the same time as running the rest of the script, about 250ms on a rpi1, so runtime can be halved if there's no options. --- barcat | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/barcat b/barcat index ab5c023..8e104c9 100755 --- a/barcat +++ b/barcat @@ -8,8 +8,10 @@ use re '/msx'; our $VERSION = '1.07'; -use Getopt::Long '2.33', qw( :config gnu_getopt ); my %opt; +if (@ARGV) { +require Getopt::Long; +Getopt::Long->import('2.33', qw( :config gnu_getopt )); GetOptions(\%opt, 'ascii|a!', 'color|c!', @@ -92,6 +94,7 @@ GetOptions(\%opt, ); }, ) or exit 64; # EX_USAGE +} $opt{width} ||= $ENV{COLUMNS} || qx(tput cols) || 80 unless $opt{spark}; $opt{color} //= -t *STDOUT; # enable on tty -- 2.30.0