Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

glob an array?

by morgon (Priest)
on Oct 20, 2018 at 01:10 UTC ( [id://1224367]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1224367]
Approved by Athanasius
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found