This pertains to the second item you bring up.
I'm not 100% sure why you need to 'do it all in one go' as you say, so this may or may not be helpful. But, adapted from a node by an anonymous monk posted
here, you can generate a list of directories within a specified directory.
You can use this to make your script adapt in case the number of or name of directories varies from run to run.
This:
#!/usr/bin/perl -w
use Data::Dumper;
while(<*>){
push(@files,$_) if(-d "$_");
}
print "\n". Dumper(@files) ."\n";
will produce output like this:
sean@seanc:~/code/temp$ ls -l
total 16
drwxr-xr-x 2 sean sean 4096 2008-09-17 09:12 dir1
drwxr-xr-x 2 sean sean 4096 2008-09-17 09:12 dir2
drwxr-xr-x 2 sean sean 4096 2008-09-17 09:12 dir3
-rwxr-xr-x 1 sean sean 155 2008-09-17 09:11 dir_list.pl
-rw-r--r-- 1 sean sean 0 2008-09-17 09:12 file1
-rw-r--r-- 1 sean sean 0 2008-09-17 09:12 file2
-rw-r--r-- 1 sean sean 0 2008-09-17 09:12 file3
sean@seanc:~/code/temp$ ./dir_list.pl
$VAR1 = 'dir1';
$VAR2 = 'dir2';
$VAR3 = 'dir3';
so you can always have an up-to-date list of subdirectories, and the code looks prettier than having a big, long hard-coded list.
Changing the '-d' to a '-f' would give you a list of files, so you could adapt that to get a list of directories, then get a list of filenames or check for the presence of a particular file.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.