in reply to RegEx Help

@Files =( "filename=merilyn14.jpg.jpeg", "filename=...) $file = "filename=merilyn14.jpg.jpeg"

mmmh... That seems a strange way to me to call a file, a source of potential troubles with your script in the future, "filename=merilyn14.jpg.jpeg" is not a file, nor even a filename, I will fix this if I were you.

$file = "merilyn14.jpg.jpeg"

more questions

print "FoxyM New fold = $nFold file = $nFile\n";

Maybe you will prefer this, probably less ambiguous and more readable, form...

print "FoxyM New fold = ", $nFold, " file = ",$nFile, "\n";

And

foreach my $file (@Files) { if ($file =~ m/filename=(\d.*?)([a-zA-Z].*?)\.j/i)

... same as:

foreach my $file (@Files) { if (/^filename=(\d.*?)([a-zA-Z].*?)\.j/)

Don't need to use /i in the match if you are using also a-zA-Z

Replies are listed 'Best First'.
Re^2: RegEx Help
by ww (Archbishop) on Dec 17, 2011 at 22:11 UTC
    ++ for the rest, but "wrong" to your final comment:

    The /i has no impact with the character class ... but may very well have to do with the "j". If OP was concerned about the various combinations of .jpg, .JPG, Jepg, JPEG and so on, then the /i is, in fact, very much needed.

    Updated to clarify the last sentence above

      I didn't see the extension. Welldone, smart note...

      But, although you are pointing in the right way, in this particular case could be a false problem...

      Remember, this is what we are really feeding to the script.

      @Files =( "filename=merilyn14.jpg.jpeg", "filename=003_Merilyn23.jpg.jpeg", "filename=890FoxyM.jpg.jpeg", "filename=006.jpg.jpeg" );

      At least in some operative systems "filename=merilyn14.jpg.JPEG" will never be evaluated or modified by the regexp, because is not in the foreach loop, so be aware of this point. We can safely avoid /i here if we are in Linux, cause its our duty to check before what we put in @Files, and even if it was one or several JPG we should change only the regexp for those matches. There is not point into having a regexp searching something that we know will never match.

      You say "/i has no impact with the character class". Which in this case is true as the class is [A-Za-z] but is not generally true:
      perl -Mre=debug -e'/[a-z]/i' Compiling REx "[a-z]" Final program: 1: ANYOF[A-Za-z][] (12) 12: END (0) stclass ANYOF[A-Za-z][] minlen 1 Freeing REx: "[a-z]"
        It would probably be well (and maybe even accurate?) to assume that statements in response to a particular node or question are context-sensitive; in other words, that you may wish to read replies as if they include the disclaimer "in this case, YMMV for other cases" or something similar UNLESS the writer has explicitly asserted that the statement is "generally" or "universally" true.

        Or maybe I should just include even more disclaimers. :-(
              or, maybe, ... :-;
        ?