in reply to Most efficient way to remove some text from a string
I don't understand the "... if the that variable contains an Artist (0 "/"), an Album (1 "/") , A song (2 "/")" part, but here's this:
c:\@Work\Perl\monks>perl -wMstrict -le "my @ra = ( '/Volumes/WD/Not Migrating/Music/Ana Tijoux', '/Volumes/WD/Not Migrating/Music/Eminem/Ana Tijoux/Luchin', '/Volumes/WD/Not Migrating/Music/Eminem/Ana Tijoux/Luchin/Luchin.m4 +a', ); print qq{'$_'} for @ra; ;; my $dir_level = qr{ / [^/]+ }xms; ;; my $n = 4; s{ \A (?: $dir_level){$n} / }{}xms for @ra; print qq{'$_'} for @ra; ;; for my $s (@ra) { my $n_fs = $s =~ tr{/}{}; my $indent = ' '; printf qq{%s'$s' \n}, $indent x $n_fs; } " '/Volumes/WD/Not Migrating/Music/Ana Tijoux' '/Volumes/WD/Not Migrating/Music/Eminem/Ana Tijoux/Luchin' '/Volumes/WD/Not Migrating/Music/Eminem/Ana Tijoux/Luchin/Luchin.m4a' 'Ana Tijoux' 'Eminem/Ana Tijoux/Luchin' 'Eminem/Ana Tijoux/Luchin/Luchin.m4a' 'Ana Tijoux' 'Eminem/Ana Tijoux/Luchin' 'Eminem/Ana Tijoux/Luchin/Luchin.m4a'
Update: Changed name of regex variable $dir to more descriptive $dir_level
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Most efficient way to remove some text from a string
by adamZ88 (Beadle) on Dec 07, 2016 at 20:18 UTC | |
by AnomalousMonk (Archbishop) on Dec 08, 2016 at 00:51 UTC |