I doubt that you will actually need "the most efficient way" which would mean some sort of performance objective to me. My advice is to do the job in a way that you can understand. All of the Perl ways will run quickly. Worry about efficient after you get something that works and that you understand how it works.

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 ' ];

In reply to Re: Most efficient way to remove some text from a string by Marshall
in thread Most efficient way to remove some text from a string by adamZ88

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.