morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

just for curiosity...

If I have an array of filenames and a glob-pattern (as e.g. "*.hubba"), is there a way to "glob" the array (i.e. get the list of all elements matching the glob-pattern) using the same logic "glob" would use, or would I have to translate the gob-pattern into a regex and do a grep?

Many thanks!

Replies are listed 'Best First'.
Re: glob an array?
by ikegami (Patriarch) on Oct 20, 2018 at 01:59 UTC
      Thx.
Re: glob an array?
by Marshall (Canon) on Oct 20, 2018 at 03:36 UTC
    To get a subset of an array, with a particular suffix, use grep().
    my @subset = grep{/\.hubbba$/}@array; #update added initial regex delimiter thanks [johngg] and [1nickt]
    A reply falls below the community's threshold of quality. You may see it by logging in.