Hi Peter.

Peter wrote:
> I'm trying to figure out how to use File::Find to print the names
> of all the files in selected directories below my working
> directory, but when I run the following script with more than one
> directory name listed on the command line, as in:
>
> $ ./find_practice dir1 dir2
>
> or
>
> $ ./find_practice dir*
>
> ...I get no output at all.
>
> Here's the script:
>
> -------------------------------------
>
> #!/usr/bin/perl
>
> use strict;
> use File::Find;
>
> @ARGV = qw(.) unless @ARGV;

I'd use the more obvious

  @ARGV = '.'

here, rather than 'qw' which is a whitespace-separated list of strings.

> print "@ARGV\n";
> find sub {
>     print "currently reporting from: $File::Find::dir\n";
>     print "$File::Find::name\n";

Nothing wrong here, but do you know that $_ is set to the file name here
(without the path) and your default directory is set to $File::Find::dir?

> }, "@ARGV";

Here's your problem. If you put quotes around an array you'll get
a single string which is all of the array elements separated by a
space. In your example you'd get

  "dir1 dir2"

but what you actually want is the list of root directories. Just

  find sub {
    :
  }, @ARGV;

will do it.

> This works find with no command line arguments.

Because you then default @ARGV to ('.') and "@ARGV"
will just be '.'.

> Doesn't "@ARGV" contain a list of arguments, which in this
> case are directories to be traversed?

Exactly right!

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to