Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Keep It Simple, Stupid
 
PerlMonks  

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

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (19)
    As of 2014-04-16 17:37 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (433 votes), past polls