in reply to Re^3: Use Of Glob On File Extensions (find/rule)
in thread Use Of Glob On File Extensions

Hmmm, thank you for your help Anonymous Monk. I think I might have bit off a bit more than I can chew right now with my level of Perl.

I know this isn't right, but am I heading in the right direction?

#!/usr/local/bin/perl use strict; use warnings; use File::Find; my @argv; my $dir = $ARGV[0]; find(\&recursiveDir, $dir); sub recursiveDir{ my @directories = glob "*"; if (-d) { opendir(DIR, $dir); while(readdir DIR) { my @files = glob "${dir}/*pl"; foreach (@files) { next if -d; (my $txt = $_) =~ s/pl$/txt/; rename($_, $txt); closedir (DIR); } } } }

I am trying to grab all files and directories and store them into an array, then traverse through it like that.

Replies are listed 'Best First'.
Re^5: Use Of Glob On File Extensions (find/rule)
by Anonymous Monk on Nov 19, 2014 at 02:01 UTC
    I'm not sure why you're so determined to use glob. No, you're not heading in the right direction, File::Find doesn't work like that at all.

      I figured it out! I was just being stubborn with glob. I had to read up on the tutorial involving the File::Find for a while until I understood what was going on. This is what I came up with.

      #!/usr/local/bin/perl use strict; use warnings; use File::Find; my @argv; my $dir = $ARGV[0]; find(\&dirRecurs, $dir); sub dirRecurs{ if (-f) { (my $txt = $_) =~ s/pl$/txt/; rename($_, $txt); } if (-d) { (my $txt = $_) =~ s/pl$/txt/; rename($_, $txt); } }

      Thank you for helping me out Anonymous Monk, it is greatly appreciated!

        I copied the wrong thing. This is what I came up with..

        #!/usr/local/bin/perl use strict; use warnings; use File::Find; my @argv; my $dir = $ARGV[0]; find(\&dirRecurs, $dir); sub dirRecurs{ if (-f) { (my $txt = $_) =~ s/pl$/txt/; rename($_, $txt); } }