There are two really big red flags here (thanks
Dominus).
First, you have a group of variables that are all named
similarly; you should be using an array instead, e.g.
@dir_vn (which would then have 6 elements). If
they were named similarly but were distinguished by some
"property name" (instead of a number, as here) you would
probably want a hash; for example,
$animal_name, $animal_color, $animal_food
becomes
%animal with name, color, and food as
keys.
Second, you're repeating essentially the same block of code
six times! Ouch. Clearly you need some sort of loop.
Happily, you recognized that something's not quite right here.
It turns out that you don't even need the array at all;
the only place it ends up being used is in the loop control
statement. See below.
#!/usr/local/bin/perl
my $dir_split = '/opt/stats/data/split';
for $dir ($dir_split, map { $dir_split . "/vn$_" } 1..6) {
opendir DIR, $dir or die $!;
my @files = grep -f "$dir/$_", readdir DIR;
# the chomp was unnecessary
closedir DIR;
chdir($dir);
unlink @files or die $!;
}
hdp.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.