Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Log parsing question

by eighty-one (Curate)
on Sep 17, 2008 at 13:25 UTC ( [id://711991]=note: print w/replies, xml ) Need Help??


in reply to Log parsing question

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://711991]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-18 17:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found