Yesterday I wrote ~50 lines of Perl that solved a one-off problem. In among that was a group of simple regexes that I am sure could be combined or written better if only I knew how. So I'd like to learn more, if someone would be kind enough to go all Perlmonks on me or attempt a Socratic dialogue. The code I wrote is:
my $plsname = $curdir; $plsname =~ s/^\Q$startdir\E//i; $plsname =~ s/\//_/g; $plsname =~ s/^_?//; $plsname .= '.pls';
with (e.g.) $curdir = 'Y:\Music\Schubert\Lieder\Terfel', $startdir = 'Y:\Music' and wanting 'Schubert_Lieder_Terfel.pls'
I tried to combine the second and fourth lines of the snippet, but while I think I could have solved that on my own, I realised that I was going to need multiple regexes and idleness set in. I suspect I should need only one regex, but my thinking processes are flawed.
What the rest of the code is doing is using File::Find to recurse through every subdirectory in the start directory and write a playlist file to another location. I have some 6,700 files in 300 directories. I now have a playlist for every directory, which is what I wanted.
Regards,
John Davies
In reply to Combining regexes by davies
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |