Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: read the whole folder files

by halfcountplus (Hermit)
on Apr 09, 2012 at 20:23 UTC ( [id://964199]=note: print w/replies, xml ) Need Help??


in reply to read the whole folder files

in the grep, you have a regex, with a rather strange looking pattern.

Ditto. Maybe you've confused shell globbing with regular expressions? Let's break this is down:

_*_.txt

"_*_" would mean, zero or more instances of "_", with a "_" following. Then "." matches any character.

If you want to match _one_.txt, _two_.txt, etc, you should use:

_.+?_\.txt

Which means: a "_" followed by one or more of anything, non-greedily (because + is followed by ?, but note ? has another meaning in regexps depending on context; non-greedy matching is important when you are looking for any number of anything, followed by something in particular), then "_." (notice the . is escaped with \ because . alone has a special meaning, see above) followed by "txt".

If you haven't yet: perlretut.

Replies are listed 'Best First'.
Re^2: read the whole folder files
by Marshall (Canon) on Apr 09, 2012 at 23:18 UTC
    I like your explanation.

    However it should be noted that there are limits to "greediness". The regex will be as "greedy" as it can be while still allowing the rest of the regex to match. In this case, anchoring the regex to the "end of string" makes a difference.
    /_.*_\.txt$/- the characters "gobbled up" by the .* won't include the "_.txt" at the end of the string.

    Having said that, I am confused by the OPs updated comment because what we were talking about had to do the how to get the file names and not parsing the file contents itself - which is a different question!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://964199]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found