in reply to Re: Perl script does not work on other directories?
in thread Perl script does not work on other directories?

Here is my last attempt. This will print directories then files and you can traverse directories easily. typing ".." at "enter path" will get you to parent dir
use strict; use warnings; use diagnostics; use File::Slurp; use Cwd; for(;;){ my @files; my $dir; print "enter path: "; chomp( $dir = <STDIN> ); chdir($dir); $dir = getcwd($dir); print $dir; # print "enter match string: "; # chomp( my $string = <STDIN> ); @files = read_dir($dir); foreach my $element (@files) { next if -f $element; print "$element\n"; } foreach my $element (@files) { next if -d $element; print "$element\n"; } print "\ncurrent dir is: $dir\n"; print "\n"; system("pause"); system("cls"); }

Replies are listed 'Best First'.
Re^3: Perl script does not work on other directories?
by james28909 (Deacon) on Nov 26, 2014 at 17:32 UTC
    i was trying to figure out how to sort the -d and -f without having to use two loops. but i am unsure how to use sort to do such a thing.

      You want to compare one thing, and then if it's the same, compare something else, and continue until you're sure they're both identical.

      @results = sort { MostImportantFeature($a) <=> MostImportantFeature($b) or NextFeature($a) <=> NextFeature($b) or LeastImportantFeature($a) <=> LeastImportantFeature($b) } @source;
        awesome. thanks for making it very simple to understand haha