in reply to Re: finding a file exist amongst many files
in thread UPDATE :: finding a file exist amongst many files

thanks for the reply steve. basically i am looking for if a file with tpsm_x exists, so on the shell it is pretty easy to find this. i want to know its perl counterpart, nevertheless i can try this but i don't want to install this package(legacy code issues).

  • Comment on Re^2: finding a file exist amongst many files

Replies are listed 'Best First'.
Re^3: finding a file exist amongst many files
by Corion (Patriarch) on Aug 25, 2016 at 14:22 UTC
Re^3: finding a file exist amongst many files
by stevieb (Canon) on Aug 25, 2016 at 14:27 UTC

    Take two, with builtins only. Note that with readdir, it doesn't keep the whole path, so you have to add it back manually:

    use warnings; use strict; my $dir = 'test'; opendir my $dh, $dir or die $!; while (readdir $dh){ if (/tpsm_.*/ && -f "$dir/$_"){ print "$dir/$_ is a file\n"; } }

    update: or use glob as Corion said :)