in reply to how do I shorten code

Use grep to select the files you want using whatever tests you like linked with and. Get the list using glob

my $dir = 'c:'; my @list = grep { m!^\Q$dir\E/B.+txt$!i and -M $_ < 1 } glob( "$dir/*" + ); print "$_\n" for @list;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: how do I shorten code
by Util (Priest) on May 09, 2003 at 02:59 UTC
    On a case-insensitive file system (Windows), you can shorten even further by specifying the pattern in the glob:
    my @list = grep { -M < 1 } glob "$dir/B*.txt";

      Theoretically, you should be able to do something similar on case sensitive systems.

      my @list = grep( -M < 1 } glob "$dir/b*.txt $dir/B*.txt";

      I say theoretically as I don't such a system to test it on, but the multiple args in a string seems to work ok. Of course if its not just the 'B' that can vary case, then enumerating all the Txt TXt TXT tXT txT TxT tXt etc. isn't going to shorten anything:)


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller