in reply to Re: Most efficient way to remove some text from a string
in thread Most efficient way to remove some text from a string

I have very little done so far

open(FILEREAD, "</home/zzz/Desktop/Scripting/usb/musicLibrary.txt"); while ($aPath = <FILEREAD>) {chomp ($aPath); my $file =~ s/$sPath/Totally/; print "This Path $file \n\n";} close (FILEREAD);

Replies are listed 'Best First'.
Re^3: Most efficient way to remove some text from a string
by poj (Abbot) on Dec 06, 2016 at 21:26 UTC

    This prints only the artist, album or track name

    #!perl use strict; #my $infile = '/home/zzz/Desktop/Scripting/usb/musicLibrary.txt'; #open IN,'<',$infile or die "Could not open $infile $!"; #while (<IN>){ while (<DATA>){ chomp; my @f = split '/',$_; my $tab = ' ' x (@f-6); print $tab.$f[-1]."\n"; } __DATA__ /Volumes/WD/Not Migrating/Music/Ana Tijoux /Volumes/WD/Not Migrating/Music/Ana Tijoux/Luchin /Volumes/WD/Not Migrating/Music/Ana Tijoux/Luchin/Luchin.m4a /Volumes/WD/Not Migrating/Music/Ana Tijoux/Kaos/ /Volumes/WD/Not Migrating/Music/Ana Tijoux/Kaos/Intro.m4a /Volumes/WD/Not Migrating/Music/Ana Tijoux/Kaos/Gol.m4a /Volumes/WD/Not Migrating/Music/Ana Tijoux/Kaos/Despabílate.m4a
    poj

      This is really, really close. I like how it prints only the artist, album, or track name. Is there a way to print this output with bullets or even better, heading styles (like in word) so that when I copy the output to a word document I could "collapse" all artist thus displaying artist only. If I expand all, artist, album and tracks will be displayed. This may be outside of the scope of this forum.

        Once the data has been successfully parsed from your flat input file you can output it in any applicable hierarchical format (JSON, XML, whatever). There are many standalone data viewers for such formats which will fulfil your requirement to expand/collapse parts of the tree. I doubt that MS Word (being your choice) is one such viewer but I have not used it for a couple of decades so perhaps it has improved since.