in reply to looking for feedback on my first script
Looks good. If only my first script was so orderly...
Some things I'd do different:
my $Usage = "usage: volume root_dir subvol timeframe dateformat keep\n +"; @ARGV == 6 or die $Usage; # we need six arguments my ( $subvol_to_snapshot_arg, # this $snap_root_dir_arg, # assigns all variables $yabsm_subvol_name_arg, # in one go $timeframe_arg, # and leaves room $date_format_arg, # to comment $snaps_to_keep_arg, # what they are about ) = @ARGV;
That's a matter of style (and lazyness :-)
I'd use sprintf
which obsoletes the pad() subroutine. Expressing the if/else/elsif as a construct of ternaries (COND ? IF_TRUE : IF_FALSE) is, again, a matter of style. The sprintf being the last expression eliminates the need for an explicit return.sub create_snapshot_name { my ($min, $hr, $day, $mon, $yr) = (localtime())[1..5]; $mon++; # month count starts at zero. $yr += 1900; # year represents years since 1900. my @fields = $date_format_arg eq 'mm/dd/yyyy' ? ($mon, $day) : $date_format_arg eq 'dd/mm/yyyy' ? ($day,$mon) : die "$date_format_arg is not a valid date format"; sprintf "day=%02d_%02d_%04d,time=%02d:%02d",@fields,$yr,$hr,$min; }
edit:
Since the documentation is contained in the script, and it states
This script should not be used by the end user.
you could stick the following directive into it up front
exec "pod2man $0" if -t; # display manual page if invoked from termina +l
which can be overridden redirecting /dev/null into it as STDIN.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: looking for feedback on my first script
by thirtySeven (Acolyte) on Jan 08, 2021 at 16:27 UTC | |
Re^2: looking for feedback on my first script
by Marshall (Canon) on Jan 09, 2021 at 16:37 UTC | |
by shmem (Chancellor) on Jan 09, 2021 at 17:33 UTC | |
by Marshall (Canon) on Jan 09, 2021 at 18:48 UTC | |
by shmem (Chancellor) on Jan 09, 2021 at 19:20 UTC | |
by Anonymous Monk on Jan 09, 2021 at 20:01 UTC | |
by Marshall (Canon) on Jan 09, 2021 at 22:21 UTC | |
|