in reply to Re^5: How to look for two different file extensions?
in thread How to look for two different file extensions?

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^6: How to look for two different file extensions?

Replies are listed 'Best First'.
Re^7: How to look for two different file extensions?
by Laurent_R (Canon) on Mar 09, 2017 at 23:00 UTC
    3) Why is introducing "Perl6" in this name-dropping way to a Perl beginner a good thing?
    Because Perl 6 does exactly the right thing in this case, something that we have all hoped one day that our language would do, and precisely the thing that the original poster was hoping to work:
    > for 1..6 { say $_ if $_ == 2|3|5|8 } 2 3 5
    which is exactly how you would say it in English: "if value equals 2 or 3 or 5 or 8", which is so much easier than: "if value equals 2 or value equals 3 or value equals 5 or value equals 8".
      for (1..6) { print "$_\n" if $_ == 2 or $_ == 3 or $_ == 5 or $_ == 8 ; }
      Perl 5 does EXACTLY the right thing and is production ready. I have never hoped that your code would ever work in Perl5. Your simplified example is not the real world.
        Sure, I am doing that everyday at $work in Perl 5, but if I can save typing four times almost the same thing with just different values, then I am happier. it gives me more time to concentrate on the real problem I have to solve.

        And I am really sorry for you if you have already given up hope that programming languages could be easier.

        A reply falls below the community's threshold of quality. You may see it by logging in.

      Your code is no closer to English than

      say $_ if $_ =~ /(2|3|5|8)/;
      But even if the beginner found it for some reason more like the aforementioned European language, in which, it is to be assumed in your scenario, he has great fluency, please explain again why would it be a good idea for him to learn that syntax, which doesn't work in the language he is (a) asking about and (b) hoping to use to accomplish an actual task?

      And people say I have an agenda!


      The way forward always starts with a minimal test.

        To paraphrase the old proverb: "It doesn't matter whether it's 'closer to English' if it gives the wrong answer."

        Needs ^anchors$ if these are to be == matches. :P

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^7: How to look for two different file extensions?
by demerphq (Chancellor) on Mar 23, 2017 at 19:40 UTC

    There is *always* more than one way to do it. That doesn't mean every post should contain all of them. In particular throwing out a regexp with non-basic syntax but no explanation doesn't seem like it will make things clearer for the novice.

    There are regexes in the OP's code, and regexes are a pretty core part of "thinking perl", so i think /AN/ answer including regex would be useful. But at the same time, how helpful is it to complain about someone elses answer like that? Why not just make a post with an explanation? Anyway.

    So heres an explanation:

    $FileExt =~/ # "file extension matches ...." \A # the start of the variable \. # match a literal dot (?: # begin a set of options foo # the option itself | # OR bar # another option ) # end of option group \z # end of variable /x; # end of pattern, enable comments in the r +egex
    ---
    $world=~s/war/peace/g