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: <%-{-{-{-<
In reply to Re: Most efficient way to remove some text from a string
by AnomalousMonk
in thread Most efficient way to remove some text from a string
by adamZ88
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |