Question

Given this data

TRMMJJH12903CF8B69<SEP>SOKSZAQ12AC9070DC0<SEP>Alexandre Da Costa<SEP>Violin Concerto No.1 in G minor_ Op.26 - III. Allegro energico

TRMMOWW128F1465642<SEP>SOGELZG12A6D4F865F<SEP>Yann Tiersen<SEP>La Valse D'Amélie (Version Orchestre)

I have to weed out all of the things before the song title, which I have done successfully.

Then I must remove everything after a +, (, {, [, etc. which I have done successfully.

The part I am stuck on is, if the line has a non-English character like the Yann Tiersen song, then I must eliminate it entirely.

I have tried looking in the docs to figure out how to use \w and \s but I cannot understand how to put it into code and use it.

Here is my code:

@songs = map { chomp; (split /<SEP>/)[3] } @data;
for (my $i = 0 ; $i < @songs . length ; $i++) {

  $title = @songs[$i];
  $title =~ s/feat..*//s;
  $title =~ s/\(.*//s;
  $title =~ s/\[.*//s;
  $title =~ s/\{.*//s;
  $title =~ s/\/.*//s;
  $title =~ s/\\.*//s;
  $title =~ s/\+.*//s;
  $title =~ s/\=.*//s;
  $title =~ s/\*.*//s;
  $title =~ s/\".*//s;
  $title =~ s/\:.*//s;
  $title =~ s/\-.*//s;
  $title =~ s/\'.*//s;
  $title =~ s/\_.*//s;
  $title =~ s/\?.*//s;
  $title =~ s/\..*//s;
  $title =~ s/\!.*//s;
  $title =~ s/\;.*//s;
  $title =~ s/\&.*//s;
  $title =~ s/\$.*//s;
  $title =~ s/\%.*//s;
  $title =~ s/\#.*//s;
  $title =~ s/\|.*//s;
  $title =~ s/\@.*//s;
  $title =~ s/\.*//s;
  $title =~ s/\!.*//s;
  $title =~ s/\¿.*//s;
  $title =~ s/\¡.*//s;
  $title !~ s/[^[:ascii:]]//g;
  $title = lc($title);

  print $title, $i, "\n";

}

The output looks like this:

violin concerto no
la valse d

The second line should not be there.

Was it helpful?

Solution

use strict;
use warnings;   

my @data = ('TRMMJJH12903CF8B69<SEP>SOKSZAQ12AC9070DC0<SEP>Alexandre Da Costa<SEP>Violin Concerto No.1 in G minor_ Op.26 - III. Allegro energico', 'TRMMOWW128F1465642<SEP>SOGELZG12A6D4F865F<SEP>Yann Tiersen<SEP>La Valse D\'Amélie');

foreach (@data){
    my @split = split(/<SEP>/);
    print "$split[3]\n" unless /[^[:ascii:]]/;
}

Prints:

Violin Concerto No.1 in G minor_ Op.26 - III. Allegro energico
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top