Click here to get back home

how to process each directory

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
how to process each directory monk 02-27-2008
Posted by monk on February 27, 2008, 3:37 pm
Please log in for more thread options
Hi all, I was wondering if you guys can help me figure this out.

This is what I'm trying to do:

read in a file containing paths to directories /home/foo/logs,
etc...all fine here.
I'd like to get into those directories and process the files inside.
Problem in this part.

This is what I have:

##slurp file into @directories_to_clean blah blah blah...

foreach (@directories_to_clean){
chomp;
print "$_\n"; #testing if I got the right directories and I do
ex: /home/foo/logs


#Here is the problem. It stops below claiming there's no file or
directory.
#same thing if I try to set a variable instead of default $_

# Isn't $_ equivalent to /home/foo/logs above ???

opendir (ARCHIVE, $_) or die "what the?...$!";

Posted by nolo contendere on February 27, 2008, 3:40 pm
Please log in for more thread options
> Hi all, =A0I was wondering if you guys can help me figure this out.
>
> This is what I'm trying to do:
>
> read in a file containing paths to directories =A0/home/foo/logs,
> etc...all fine here.
> I'd like to get into those directories and process the files inside.
> Problem in this part.
>
> This is what I have:
>
> ##slurp file into @directories_to_clean blah blah blah...
>
> foreach (@directories_to_clean){
> =A0 =A0 chomp;
> =A0 =A0 print "$_\n"; =A0 =A0#testing if I got the right directories and I=
do
> ex: /home/foo/logs
>
> =A0 =A0 =A0#Here is the problem. =A0It stops below claiming there's no fil=
e or
> directory.
> =A0 =A0 =A0#same thing if I try to set a variable instead of default $_
>
> =A0 =A0 =A0 # =A0 Isn't =A0 =A0$_ =A0 equivalent to /home/foo/logs above =
=A0 =A0???
>
> =A0 =A0 opendir (ARCHIVE, $_) or die "what the?...$!";

Can you post a workable piece of code, along with the actual message
returned by Perl, along with perhaps a copy/paste of you "ls'ing" to
one of those dirs successfully?


Posted by monk on February 27, 2008, 3:48 pm
Please log in for more thread options
> Can you post a workable piece of code, along with the actual message
> returned by Perl, along with perhaps a copy/paste of you "ls'ing" to
> one of those dirs successfully?

Here you go:

# read config file in
# add inside test.conf directories such as /home/foo/logs or whatever.
save the file.
open($log_file_handler,"<", "test.conf") or die "Can't open config file
\n";


DISTRIBUTION_CENTER:
while (<$log_file_handler>) {
chomp;
s/#.*//; # Remove comments
s/^ *//; #Remove leading spaces
s/ *$//; #Remove trailing spaces
next DISTRIBUTION_CENTER if /^(\s)*$/; # skip blank lines

push @directories_to_clean, $_; #add entries to an array

}


#it's supposed to go inside each directory
foreach (@directories_to_clean){
chomp;
print "$_\n"; #testing if I got the right directories and I do
ex: /home/foo/logs
opendir (ARCHIVE, $_) or die "what the?...$!";
chdir $_; #it doesn't get this far

}

ERROR: what the hell?...No such file or directory.

Posted by nolo contendere on February 27, 2008, 4:02 pm
Please log in for more thread options
> > Can you post a workable piece of code, along with the actual message
> > returned by Perl, along with perhaps a copy/paste of you "ls'ing" to
> > one of those dirs successfully?
>
> Here you go:
>
> # read config file in
> # add inside test.conf directories such as /home/foo/logs or whatever.
> save the file.
> open($log_file_handler,"<", "test.conf") or die "Can't open config file
> \n";
>
> DISTRIBUTION_CENTER:
> while (<$log_file_handler>) {
> =A0 =A0 =A0 =A0 chomp;
> =A0 =A0 =A0 =A0 s/#.*//; # Remove comments
> =A0 =A0 =A0 =A0 s/^ *//; #Remove leading spaces
> =A0 =A0 =A0 =A0 s/ *$//; #Remove trailing spaces
> =A0 =A0 =A0 =A0 next DISTRIBUTION_CENTER if /^(\s)*$/; =A0# skip blank lin=
es
>
> =A0 =A0 =A0 =A0 push @directories_to_clean, $_; #add entries to an array
>
> }
>
> #it's supposed to go inside each directory
> foreach (@directories_to_clean){
> =A0 =A0 chomp;
> =A0 =A0 print "$_\n"; =A0 =A0#testing if I got the right directories and I=
do
> ex: /home/foo/logs

Here, try:
if ( -d $_ ) {
print "this is a directory\n";
else {
print ">>$_<< is not a directory.\n";
}

> =A0 =A0 opendir (ARCHIVE, $_) or die "what the?...$!";
> =A0 =A0 chdir $_; =A0#it doesn't get this far
>
> }
>
> ERROR: what the hell?...No such file or directory.


Posted by monk on February 27, 2008, 4:17 pm
Please log in for more thread options
I get from the shell:

<< is not a directory.r/logs
what the hell?...No such file or directory

Then I do a manual regular cd command to the directory logs and I'm
in.
Even with the full path which the program itself printed with print "$_
\n";

any clues?

Similar ThreadsPosted
Parent process unable to read messages from child process February 28, 2007, 12:38 pm
Parent process unable to read messages from child process February 28, 2007, 12:38 pm
what is %process XX% October 28, 2004, 1:12 pm
PLEASE help me with this process June 17, 2005, 1:18 pm
get process name from process id July 17, 2008, 1:18 pm
killing a process using its PID September 13, 2004, 4:51 pm
process control September 28, 2004, 12:12 am
Need help with the "System" process April 11, 2006, 8:14 am
kill the process July 7, 2006, 3:51 pm
Perl API to be used as process. November 29, 2006, 7:39 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap