E
eyal.susser
Hi,
I'm working on a Fedora Core 3 machine. I am also a perl newbie. I
would like to write a script that iterates through directories and
finds files with specific attributes.
I wrote a subroutine called scan:
sub scan
{
$dirname = shift;
open(DIRAHNDLE , $filename);
@contents = <$dirname . "/*">
close(DIRHANDLE);
foreach $member (@contents)
{
if(-d $member)
print("Dir: " . $dirname . "/" . $member);
else
print("File: " . $member);
}
}
This was just for testing. I ran it on /home/username, and have
several problems:
1. I get a result like /home/username/home/username, probably because
of the . directory
2. I get a list of all the files and directories under / ! Why is
that?
3. So how do I write a script that does what I want? I wanted to use
recursion, but with these wacky results, it would lead to an infinite
loop!
I'm working on a Fedora Core 3 machine. I am also a perl newbie. I
would like to write a script that iterates through directories and
finds files with specific attributes.
I wrote a subroutine called scan:
sub scan
{
$dirname = shift;
open(DIRAHNDLE , $filename);
@contents = <$dirname . "/*">
close(DIRHANDLE);
foreach $member (@contents)
{
if(-d $member)
print("Dir: " . $dirname . "/" . $member);
else
print("File: " . $member);
}
}
This was just for testing. I ran it on /home/username, and have
several problems:
1. I get a result like /home/username/home/username, probably because
of the . directory
2. I get a list of all the files and directories under / ! Why is
that?
3. So how do I write a script that does what I want? I wanted to use
recursion, but with these wacky results, it would lead to an infinite
loop!