in reply to Perl List files in directory

In your Option 2, try my @files = glob("/opt/tmp/*");, otherwise you'll only get files that include a dot in the name.

In your Option 3, the opendir line should be: opendir(DIR, "/opt/tmp/") or die "Cannot open dir"; (misplaced closing paren). Also, the grep causes @files to only include "text" files (see documentation of -T in -X), is that what you want?

Replies are listed 'Best First'.
Re^2: Perl List files in directory
by Anonymous Monk on Apr 22, 2014 at 10:46 UTC

    No, my directory contains xml files. I will take a look at the documentation.

    Thanks for the help

      Depending on the encoding of your XML files, the -T test may or may not recognize them as "text" files. From -X:

      The -T and -B switches work as follows. The first block or so of the file is examined for odd characters such as strange control codes or characters with the high bit set. If too many strange characters (>30%) are found, it's a -B file; otherwise it's a -T file. Also, any file containing a zero byte in the first block is considered a binary file.