Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Regular expression to list all files of type in folder

by 2teez (Vicar)
on Dec 05, 2012 at 21:40 UTC ( [id://1007405]=note: print w/replies, xml ) Need Help??


in reply to Regular expression to list all files of type in folder

try this: next unless ($file =~ m/.+?\.jpg$/);
Please, always check the return of your open function like so: open ... or die "can't open file: $!"; or use autodie

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: Regular expression to list all files of type in folder
by runrig (Abbot) on Dec 05, 2012 at 21:48 UTC
    Why would that regex match if the other doesn't?

      The OP said the other does match. Please, check the OP last statement.
      "..The problem is I have a file named "test.jpg" and another called "testl.jpg" and the expression only picks up the first one. Other than that, it works fine..."

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me
        Unless I'm mistaken and missed some un-commented update, you added a '.+?' to the beginning of the OP's regex. So I still don't understand why you think that will match any better, as the '.+?' is superfluous.
Re^2: Regular expression to list all files of type in folder
by ww (Archbishop) on Dec 05, 2012 at 22:16 UTC
    UPDATE: I addressed my answer to the wrong node. 2teez initial node was modified after runrig pointed out the open issue. So please read this as if addressed, as intended, to 2teez. </UPDATE>
    It's highly impolite to modify your (mistaken) post without acknowledging the update.

    <UPDATE3 with strikeout in light of the reply, ack'ing that the sequence he asserts might have coincided nearly simultaneously with what I saw.> It's even more so when you ADD a suggestion made by another Monk that was not included in your own original, inaccurate (and apparently, untested) advice. <RESUMING UPDATE3 NOTE: I continue to held the view that "your own original, inaccurate (and apparently, untested) advice...." was ill-considered.</RESUMING...>

    - -, and dog votes be damned.

    P.S. (and yes, this is an update, too) It's also wise to test your code (and that to which you're responding) to make sure yours
        a) does what you thought it should do...
            and
        b) that your solution actually solves or illuminates OP's problem.

      Hi ww,
      I cannot be more surprise than anything else than your comment, as regard my initial OP. After I came to this thread.
      Indeed had posted a solution, which stated as this Use this: next unless ($file =~ m/.+?\.jpg$/);
      then added this: Please, always check the return of your open function like so: open ... or die "can't open file: $!"; or use autodie
      Only for me to go back into the "thread" to see that runrig had posted this:...Also, unless you're using autodie, you should check the status of open and opendir.

      On my honor, I didn't update my regex used in my initial OP, neither did I updated my post after seeing runrig post.
      Probably, the only mistake I made was not to have put a word out that I wasn't updating my post after seeing that of runrig.
      Infact, to prove that, why was opendir not included in my "update"? If I had seen that of runrig before writing mine.

      Please, if you may, check my other post before now. I had shown Update, when my initial post had been updated. Acknowledged, when the original thought was not mine, been grateful with an update of the monks name when I was corrected on some post.
      I feel so hurt here, because I had been called a "thief" but in a polite way.
      I believe your assessment of what went down here is WRONG, please.

      Update:
      Sorry, I didn't include this: Except for changing the usage of "Use this" to "try this:" I didn't update anything else.
      And I did that because I felt that using "Use this", was not polite enough.
      And if I had wanted to lie about this, I would not be including this.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-20 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found