develooper Front page | perl.perl5.porters | Postings from January 2015

Re: [perl #123691] Feature: A variation of glob() which uses regexps

Thread Previous | Thread Next
From:
Ricardo Signes
Date:
January 29, 2015 13:57
Subject:
Re: [perl #123691] Feature: A variation of glob() which uses regexps
Message ID:
20150129135715.GA24688@cancer.codesimply.com
* Victor Porton <porton@narod.ru> [2015-01-29T08:33:01]
> 29.01.2015, 13:51, "James E Keenan via RT" <perlbug-followup@perl.org>:
> > On Wed Jan 28 10:39:13 2015, porton@narod.ru wrote:
> >>  I suggest to add to Perl core a routine similar to glob(), but
> >>  using regexps instead of globs.
> >
> > But that functionality already exists, does it not?
> >
> > opendir my $DIR, 'some/directory' or die;
> > my @files = grep { m/some_pattern/ } readdir $DIR;
> > closedir or die;
> 
> It is better to do it in one line rather than three ones.

  my @files = grep { m/some_pattern/ } <$d/* $d/.*>;

  # or

  my @files = grep { m/some_pattern/ } IO::Dir->new($d)->read;

I agree it's more typing than

  my @files = readdir_matches($dir, $qr);

...but not a whole lot.  Really, this seems like a great job for CPAN.  There's
nothing core-specific about the feature, and you could start using it today
instead of May 2016.

Personally, I'd use IO::Dir.

-- 
rjbs

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About