Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

XML::XPath matching different file extension

by Anonymous Monk
on Apr 13, 2021 at 15:27 UTC ( #11131194=perlquestion: print w/replies, xml ) Need Help??

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

Hi there Monks!

I have this line in my code and I am trying to see if there is a way to add more than one file match in this line, the files comes as "*.txt", "*.TXT", "*.png", "*.PNG".
It breaks if in this line the file extension is "*.TXT" instead of "*.txt".
my @files = $zip->membersMatching( '.*\.txt' );

Thanks for looking!

Replies are listed 'Best First'.
Re: Archive::Zip matching different file extension
by haukex (Bishop) on Apr 13, 2021 at 15:32 UTC

    I assume you meant Archive::Zip instead of XML::XPath? At least according to the documentation, this should work: my @files = $zip->membersMatching( qr/\.(?:txt|png)$/i );

      Thank you!!
        FYI, in the Perl world it is very common to find that for your convenience a library will accept either a string-pattern or a regular expression as an argument. Regular expressions, as haukex just demonstrated, are by far the most powerful alternative.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11131194]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2021-05-18 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (176 votes). Check out past polls.

    Notices?