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:
And is that really any better? Again, your call.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'
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
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.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'
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |