http://www.perlmonks.org?node_id=11126614


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

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; }
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.

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.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'