I didn't think the OPed code was really so terrible to begin with (once the  $plsname =~ s/\//_/g; statement is fixed). But in an attempt to "one-liner-ize" the code, and building on BrowserUk's post (and using my preferred regex practices), here's this:

c:\@Work\Perl\monks>perl -wMstrict -le "my $curdir = 'Y:\Music\Schubert\Lieder\Terfel'; my $startdir = 'Y:\mUsIc'; ;; my $plsname = $curdir; $plsname =~ s{ \A (?i) \Q$startdir\E \\ (.+) \z } { (my $r = $1) =~ tr{\\}{_}; $r . '.pls'; }xmse; print qq{'$plsname'}; " 'Schubert_Lieder_Terfel.pls'
And is that really any better? Again, your call.

If you have Perl version 5.14+, it's possible to slightly simplify the  s/// replacement executable code above to
    $1 =~ tr{\\}{_}r . '.pls';
and in fact you could go all the way to

c:\@Work\Perl\monks>perl -wMstrict -le "my $curdir = 'Y:\Music\Schubert\Lieder\Terfel'; my $startdir = 'Y:\mUsIc'; ;; my $plsname = $curdir =~ s{ \A (?i) \Q$startdir\E \\? }{}xmsr =~ tr{\\}{_}r . '.p +ls'; print qq{'$plsname'}; " 'Schubert_Lieder_Terfel.pls'
I hope this hasn't gone too "all PerlMonks" on you, and includes at least a hint (update: but not a single drop!) of Socrates.

Update: For info on the  /r modifier added in Perl version 5.14, see  s/// in Regexp Quote-Like Operators and  tr/// in Quote-Like Operators, both in perlop.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Combining regexes by AnomalousMonk
in thread Combining regexes by davies

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.