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

regex to capture files that start with a lowercase letter

by fionbarr (Friar)
on Feb 13, 2015 at 18:16 UTC ( [id://1116639]=perlquestion: print w/replies, xml ) Need Help??

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

amended example....fixing typo
my @files = grep ( /[a-z].+\.txt/, readdir($dh));
This does not work.

Replies are listed 'Best First'.
Re: regex to capture files that start with a lowercase letter
by toolic (Bishop) on Feb 13, 2015 at 18:29 UTC
    From your considered post:
    I want to capture *.txt files that begin with a lower-case letter.
    Anchor the pattern:
    my @files = grep ( /^[a-z].+\.txt/, readdir($dh));
      of course, thanks
Re: regex to capture files that start with a lowercase letter
by RichardK (Parson) on Feb 13, 2015 at 18:46 UTC

    But it's still easier to use glob ;)

    my @files = glob('[a-z]*.txt');
Re: regex to capture files that start with a lowercase letter
by Anonymous Monk on Feb 13, 2015 at 18:20 UTC

    Please fix the original post instead of creating new duplicate thread.

Re: regex to capture files that start with a lowercase letter (path tiny)
by Anonymous Monk on Feb 13, 2015 at 22:09 UTC
    readdir is low-level, avoid it , use Path::Tiny
    use Path::Tiny qw/ path /; my @files = path( 'anypath' )->children( qr/^[a-z].+\.txt$/ );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found