True, it's more readable to have an expression and the kind-of-best way is the one with two expressions. To make this quite efficient and readable, a prepost($name,$prefix,$postfix) function using substr inside would be the solution if this problem occurs more than once. This is hypothetical, it's perhaps only 30 lines of code where neither speed nor readability matter :)

About /x: I'm starting to use it nearly everywhere, i don't think it makes anything harder to read. Perl 6 regular expressions (which are then somehow comparable to Parse::RecDescent now) are /x'ed by default, getting used to this is probably helpful. Imho it makes any expression more readable, at least after you're used to it. You see this differently, because you're probably used to compact expressions because they are common in Perl 5. Try forcing yourself to make everything very optical via /x and you'll change your mind in a week.

--
http://fruiture.de

In reply to Re: Re: Re: Reg Expression on file name by fruiture
in thread Reg Expression on file name by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.