in reply to No Filenames Returned

You never call your subroutine processFiles, so it never gets executed. I think you want to put the following into your script to help tracing what it does:

print "$0 started at " . localtime; processFiles(@ARGV); print "$0 finished at " . localtime;

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

    ah, silly me. Okay, I also added suggested code and get the below,

    racket@ibmlap perl$ ./dirrecur . Unable to open 1: No such file or directory at ./dirrecur line 6. ./dirrecur started at Thu Mar 23 17:49:31 2006racket@ibmlap perl$

    line 6 below,

    opendir (DIR, $path) or die "Unable to open $path: $!";

    Perhaps I'm still missing something, yes? I was following here,

    http://www.perlmonks.org/?node_id=136482

    Cheers.

    coolboarderguy...

      Please use <code> ... </code> around your code, data and console output so it renders and downloads properly (see the Writeup Formatting Tips).

      Please post the complete program you're using and how you are calling it. If you get the error message Unable to open 1, that means that perl tried to open the file 1. So likely, you are setting $path to the wrong value - check where and how you set $path.

        I used code tags for the code, but, thought, with only a line or two, of console output it wouldn't be needed...your advice is noted from now. cheers.

        coolboarderguy...

      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

        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...