Enigma
Enigma

Reputation: 315

Exclude files that end with a certain file extension

I would like to get all files in, say, the working directory, excluding files that, for example, end with .pl. So, test.pl should be excluded but not test.txt or test.xyz

The expression glob(".* *") matches all the files in a working directory and seems to be working well. Except for the part of excluding files that end with .pl. I have tried several expression including *(?!.pl), but none seem to work.

Upvotes: 3

Views: 1812

Answers (1)

toolic
toolic

Reputation: 62236

A common way is to use grep to exclude items in a list:

my @files = grep { !/\.pl$/ } glob(".* *");

Upvotes: 7

Related Questions