in reply to Re: Re: globing directory names with spaces
in thread globing directory names with spaces

Then you need to look into File::Find.
use File::Find; my @java_file; find(sub { push @java_file, $File::Find::name if /\.java$/i }, "/desired/path");

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re^2: globing directory names with spaces
by broquaint (Abbot) on Sep 16, 2002 at 15:40 UTC
    Alternatively you could use File::Find::Rule
    use File::Find::Rule; my @files = File::Find::Rule->file() ->name('*.java') ->in('your/dir/here');
    Which will return a list of all the files with the .java extension in the given directory and all of it's subdirectories.
    HTH

    _________
    broquaint

Re: Re^2: globing directory names with spaces
by abhishes (Friar) on Sep 16, 2002 at 15:24 UTC
    Hello All,
    thanks you so much for all the replies
    Here is what i wrote with File::Find
    #!/usr/bin/perl use strict; use warnings; use File::Find; my @java_files; my $pattern = shift; if ($pattern eq '') { print "defaulting the directory to the current one\n"; $pattern = '.'; } print "$pattern\n"; find(\&wanted, $pattern); foreach my $file (@java_files) { open OUTFILE, "$file"; while(<OUTFILE>) { print "$_\n"; } } my $java_files = @java_files; print "++ Total number of java files in project = $java_files\n"; sub wanted() { if (/\.java$/i) { push(@java_files, $_); } }
    The problem is that the contents of the files are not
    getting printed. because the file open is failing.
    the file open is failing because I have only the file name
    and not the complete path of the file. what can I do go get
    the complete file name in my java_file array?
      Did you read my reply? You would have noticed I was using $File::Find::name rather than $_ in the sub I pass to find because I anticipated just that problem. :-) See the docs to File::Find for more details.

      Makeshifts last the longest.