in reply to selcting all files in a given directory except......

When you use strict (which is recommended), you have to declare your variables with my:

After the readdir there is a stray closing parenthesis.

#!/usr/bin/perl use strict; use warnings; chomp(my $dir = <STDIN>); my @files; if (-d $dir){ opendir (my $DIR, $dir); @files = grep { m/^(?!\.{1,2}\z)/ } readdir($DIR); closedir($DIR); } foreach my $file (@files) { print "$file\n"; }

Replies are listed 'Best First'.
Re^2: selcting all files in a given directory except......
by Anonymous Monk on Dec 06, 2007 at 09:29 UTC
    names of the files are not been displayed .......
      The script works fine for me.

      Remember to enter a directory name and hit the Return key. And of course the name you type in has to be a valid directory.

        the code is excecuted but i had given files names as test1 test2 in directory(test) ./file test is not displaying any files jus cusor is at the starting of the below line
      A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.