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

    Sorry for the confusion. What I meant is that once I have removed the unnecessary part of the path, I would check the remaining string and count the number of forward slashes"/". If there are 0 forward slashes, this string represented an artist, if there is 1 forward slash, this string represents an album, 2 forward slashes represents a song.

      I was confused because you seem to have  /Eminem running wild through your example paths. Others have assumed this is a typo, and you've never denied this. (Nor ever confirmed it...)


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