Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (3)
    As of 2018-01-19 01:45 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (215 votes). Check out past polls.