Is there anyway to shorten this script? I think this script could be reduced to 1/6th the size, but I am not too sure what the best method is... a little lesson on perl technique anyone?

"In God we trust, all others bring data." -trowa
#!/usr/local/bin/perl # rmtree is not ideal because directory doesn't need to be unlinked, o +nly files # use File::Path; # $verbose=1; # $safe=0; # rmtree([ $dir_split, $dir_vn1, $dir_vn2, $dir_vn3, $dir_vn4, $dir_vn +5, $dir_vn6 ], $verbose, $safe); my $dir_split='/opt/stats/data/split'; my $dir_vn1='/opt/stats/data/split/vn1'; my $dir_vn2='/opt/stats/data/split/vn2'; my $dir_vn3='/opt/stats/data/split/vn3'; my $dir_vn4='/opt/stats/data/split/vn4'; my $dir_vn5='/opt/stats/data/split/vn5'; my $dir_vn6='/opt/stats/data/split/vn6'; # opendir DIR0, $dir_split || die "Cannot open $dir_split: $!"; my @files=grep {-f "$dir_split/$_" } readdir DIR0; closedir DIR0; chomp(@files); chdir("$dir_split"); unlink @files or die "unlink unsuccessful: $!"; # opendir DIR1, $dir_vn1 || die "Cannot open $dir_vn1: $!"; my @files=grep {-f "$dir_vn1/$_" } readdir DIR1; closedir DIR1; chomp(@files); chdir("$dir_vn1"); unlink @files or die "unlink unsuccessful: $!"; # opendir DIR2, $dir_vn2 || die "Cannot open $dir_vn2: $!"; my @files=grep {-f "$dir_vn2/$_" } readdir DIR2; closedir DIR2; chomp(@files); chdir("$dir_vn2"); unlink @files or die "unlink unsuccessful: $!"; # opendir DIR3, $dir_vn3 || die "Cannot open $dir_vn3: $!"; my @files=grep {-f "$dir_vn3/$_" } readdir DIR3; closedir DIR3; chomp(@files); chdir("$dir_vn3"); unlink @files or die "unlink unsuccessful: $!"; # opendir DIR4, $dir_vn4 || die "Cannot open $dir_vn4: $!"; my @files=grep {-f "$dir_vn4/$_" } readdir DIR4; closedir DIR4; chomp(@files); chdir("$dir_vn4"); unlink @files or die "unlink unsuccessful: $!"; # opendir DIR5, $dir_vn5 || die "Cannot open $dir_vn5: $!"; my @files=grep {-f "$dir_vn5/$_" } readdir DIR5; closedir DIR5; chomp(@files); chdir("$dir_vn5"); unlink @files or die "unlink unsuccessful: $!"; # opendir DIR6, $dir_vn6 || die "Cannot open $dir_vn6: $!"; my @files=grep {-f "$dir_vn6/$_" } readdir DIR6; closedir DIR6; chomp(@files); chdir("$dir_vn6"); unlink @files or die "unlink unsuccessful: $!";

In reply to arrays within arrays? by trowa

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!
  • 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, details, 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, summary, 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.