ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
because it is perl I will give it the benefit of the doubt and assume this is possible, rather than ask if it is possible I will ask how.
I am going to create a subroutine/function/meathod/whatever you want to call it to isolate the artist name in a directory of (Legal) mp3's
say it is like this:
directory:
Artist A - 22 - songa.mp3
Artist A - 22 - Songb.mp3
... the list goes on.
First off I have it strip character slike '-' and reduce all double spaces into single space, as well all characters are lowercased, also a text replacement replaces all '_' with space ' '
so what we have is:
artist a 22 songa
artist a 23 songb
artist a 24 songc
maybe one or 2 out of order or with the nunber missing
25 artist a songd
songe artist a
(By this point the .mp3 is also stripped)
I then need a way to isolate "artist a"
in other words I need it to run through all the string we now have and find a common string that at least 75% of the filenames checked have in common in this case all the files have "artist a" in there name, but nothing else would match across them. what would be the correct way to impliment such a search?
also it needs to do it on a word basis, as in "artist a songa" and "artist a songb" would only match the "artist a" not the "artist a song" because each time song is found it is followed by a character not a space, so the word as a whole is thrown away and not used in the match.
also it needs to differenciate between a number that is common and a number that is not:
say there is a band called "my number 3"
each song title would look liek this:
"my number 3 12 songname"
"my number 3 13 songnamea"
"my number 3 14 songnameb"
"my number 3 15 songnamec"
this should match "my number 3" becuase the 3 is also found in them all.
I am familiar with basic matching and some other regex, and I am very familiar with perl finishing off a class on it with 3 years+ total programming experiance, so you do not need to dumb it down to much or baby me through it.
Why are you removing the delimiter? Just use:
$song="Artist A - 22 - songa.mp3";
$song=~s/\.mp3$//;
($artist,$num,$track)=split(/ - /g,$song);
print "Artist: $artist\nTrack: $track\n";
not all the files in the directory will have the delimiter, I remove it to ensure consistancy in the procedure
and not make a special case for weather or nto there are delimeters.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.