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

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.

  • Comment on Re^4: Most efficient way to remove some text from a string

Replies are listed 'Best First'.
Re^5: Most efficient way to remove some text from a string
by hippo (Archbishop) on Dec 07, 2016 at 09:57 UTC

    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.

      I had not thought about XML!!!! Thank you!

        XML ? something like this perhaps. Open the output file with a browser to get text folding.

        #!perl use strict; use XML::Simple; #my $infile = '/home/zzz/Desktop/Scripting/usb/musicLibrary.txt'; #open IN,'<',$infile or die "Could not open $infile $!"; #while (<IN>){ my %hash=(); while (<DATA>){ chomp; if (/\.m4a$/){ my @f = split '/',$_; push @{ $hash{'artist'}{$f[-3]}{'album'}{$f[-2]}{'track'}},$f[-1]; } } open OUT,'>','report.xml' or die "$!"; print OUT XMLout(\%hash,RootName=>'records'); __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/Track3.m4a /Volumes/WD/Not Migrating/Music/Ana Tijoux/Kaos/Track4.m4a

        Be aware of the STATUS of XML::Simple and the CAVEATS within

        poj