sub nl () { print "\n"; print "\n" }
Why print twice and not just:
sub nl () { print "\n\n" }
if ($units !~ m{(K|M)B}i ) {
For single characters you should use a character class, especially when you don't need capturing parentheses:
if ($units !~ /[KM]B/i ) {
my @num = qx[du -B $units -d 1 $in_dir | cut -f 1]; my @dir = qx[du -B $units -d 1 $in_dir | cut -f 2];
my version of du doesn't have the -d switch so I couldn't test this.
if ($skip =~ m{,}) { @sks = split(',', "$skip"); $si = $#sks + 1; for (my $i = 0; $i < $in; $i++) { for (my $j = 0; $j < $si; $j++) { if ($dir[$i] =~ m{$sks[$j]}) { $num[$i] = 0 }}}} elsif ($skip !~ m{,}) { for (my $i = 0; $i < $in; $i++) { if ($dir[$i] =~ m{$skip}) { $num[$i] = 0 }}} else { print "$skip is not a directory. Please ensure $skip is a dir i +nside $in_dir." }
The test for a comma is unnecessary because split will work correctly with or without the comma. And you don't test the value of $skip so you don't know whether it is a directory or not so the print line makes no sense.
my @sks = split /,/, $skip; for my $i ( 0 .. $#num ) { for my $j ( 0 .. $#sks ) { if ( $dir[ $i ] =~ /$sks[$j]/ ) { $num[ $i ] = 0; } } }
for (my $i = 0; $i < $in; $i++ ) { my $temp = $num[$i]; if ($units =~ m{KB}) { $units =~ s{KB}{kB}g } $temp =~ s{$units}{}g; $temp =~ s{ $}{}g; chomp $temp; push @dig, $temp }
$units doesn't have to be modified every time the loop iterates, in fact it can only be modified once anyways:
$units =~ s/KB/kB/g; for my $i ( @num ) { my $temp = $i; $temp =~ s/$units//g; $temp =~ s/ $//g; chomp $temp; push @dig, $temp; }
$sum = $sum + $dig[$i];
That is usually written as:
$sum += $dig[ $i ];
if ($skip !~ "" && $skip !~ m{,}) {
According to perlop:
The empty pattern // If the PATTERN evaluates to the empty string, the last successfully matched regular expression is used instead. In this case, only the "g" and "c" flags on the empty pattern is honoured - the other flags are taken from the original pattern. If no match has previously succeeded, this will (silently) act instead as a genuine empty pattern (which will always match).
Which means that $skip !~ "" will be $skip !~ m{yes|y}i if $ARGV[2] =~ m{yes|y}i matched (or the last previously successful match.)
What you probably want is:
if ( length $skip && $skip !~ /,/ ) {
elsif ($si > 0) {
Or (what this really means):
elsif ( @sks ) {
In reply to Re: Utility to calculate best way to archive Dir to DVD
by jwkrahn
in thread Utility to calculate best way to archive Dir to DVD
by slugman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |