in reply to Re^2: No Filenames Returned
in thread No Filenames Returned

Hm, your code worked for me. It seems that, for some reason, your script is getting 1 as the pathname. So, there are three files in the same directory as the dirrecur script? What are the permissions on those? You might want to do an ls -l . from the prompt to confirm they are there. (I beleive you, but it's occam's razor - eliminate the simple things first) :) You might also try putting the following statement below your use statements:
use Carp;
and in the code, instead of die, use croak, like this (I added a carriage return at the end to make it more readable):
opendir (DIR, $path) or croak "Unable to open $path: $!\n";
That may give your more verbose information. I find it very useful in my code, as it gives a trace of the subroutine calls, values passed in, etc.

Update: here's the entire code, as it worked for me. I noticed that you had a typo in your die statement, too - it should be $!, not ! or 1.

#!/usr/bin/perl use strict; use warnings; use Carp; sub processFiles { my $path = shift; opendir (DIR, $path) or croak "Unable to open $path: $!"; my @files = readdir (DIR); closedir (DIR); foreach my $myfile (@files) { print "Files: $myfile\n"; } } print "$0 started at " . (localtime) . "\n"; processFiles(@ARGV); print "$0 finished at " . (localtime) . "\n";

-- Burvil

Replies are listed 'Best First'.
Re^4: No Filenames Returned
by coolboarderguy (Acolyte) on Mar 23, 2006 at 11:41 UTC
    Hi All,

    success. Code is below,

    #!/usr/bin/perl use strict; use warnings; sub processFiles { my $path = shift; opendir (DIR, $path) or die "Unable to open $path: $!"; my @files = grep { !/^\.{1,2}$/} readdir (DIR); closedir (DIR); foreach my $myfile (@files) { print "Files: $myfile\n"; } } print "$0 started at " . (localtime) . "\n"; processFiles(@ARGV); print "$0 finished at " . (localtime) . "\n";

    Output,

    [racket@ibmlap perl]$ ./dirrecur . ./dirrecur started at Thu Mar 23 20:37:53 2006 Files: listscalar.pl Files: dirrecur Files: testfunc ./dirrecur finished at Thu Mar 23 20:37:53 2006
    Cheers

    EDIT: This is just a piece of code for study, not of another piece of code.

    coolboarderguy...