in reply to Most efficient way to remove some text from a string
I'm not sure what the indentation level is exactly. Could it be that this "Eminem" token should be deleted it it is there?
use strict; use warnings; use Data::Dumper; my @cases=( '/Volumes/WD/Not Migrating/Music/Ana Tijoux (An Artist)', '/Volumes/WD/Not Migrating/Music/Eminem/Ana Tijoux/Luchin (An Album)', '/Volumes/WD/Not Migrating/Music/Eminem/Ana Tijoux/Luchin/Luchin.m4a ( +A Song)'); foreach my $case (@cases) { $case =~ s|^.+Music/||; # remove /Volumes/WD/Not Migrating/Music/ $case =~ s|\(.+\)||; # remove trailing (An Artist), etc. print "\nLooking at case:$case...\n"; my @parts = split ('/',$case); my $indent = 0; if (@parts == 3){$indent=1;} elsif (@parts==4) {$indent=2;} print "# parts=".@parts," , the indent level=$indent\n"; print "indent line is next:\n"; print "\t"x$indent,"$parts[-1]\n"; #use only last part?? and indent +?? print "all parts:\n"; print Dumper \@parts; } __END__ PRINTOUT: Looking at case:Ana Tijoux ... # parts=1 , the indent level=0 indent line is next: Ana Tijoux all parts: $VAR1 = [ 'Ana Tijoux ' ]; Looking at case:Eminem/Ana Tijoux/Luchin ... # parts=3 , the indent level=1 indent line is next: Luchin all parts: $VAR1 = [ 'Eminem', 'Ana Tijoux', 'Luchin ' ]; Looking at case:Eminem/Ana Tijoux/Luchin/Luchin.m4a ... # parts=4 , the indent level=2 indent line is next: Luchin.m4a all parts: $VAR1 = [ 'Eminem', 'Ana Tijoux', 'Luchin', 'Luchin.m4a ' ];
|
|---|
| 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:14 UTC | |
by Marshall (Canon) on Dec 08, 2016 at 21:59 UTC |