I have a script that parses through a database of my music to create dynamic playlists. It reads in a text file with input criteria. At one point, my code parses through the text file looking for input variables, like so:
### Find values to be included. Maybe there is a way to do this in a + loop? ($inc_albums)=$content=~/inc_albums=(.*?)\n/; ($inc_genres)=$content=~/inc_genres=(.*?)\n/; ($inc_artists)=$content=~/inc_artists=(.*?)\n/; ($inc_songs)=$content=~/inc_songs=(.*?)\n/; ($inc_ratings)=$content=~/inc_ratings(.*?)\n/; ($inc_year)=$content=~/inc_year(.*?)\n/; ### Find values to be excluded ($exc_albums)=$content=~/exc_albums=(.*?)\n/; ($exc_genres)=$content=~/exc_genres=(.*?)\n/; ($exc_artists)=$content=~/exc_artists=(.*?)\n/; ($exc_songs)=$content=~/exc_songs=(.*?)\n/; ($exc_ratings)=$content=~/exc_ratings(.*?)\n/; ($exc_year)=$content=~/exc_year(.*?)\n/;
you can see the repetitive pattern here. I have this suspicion, that I could could all of this with a 2 or 3 line loop. I also suspect that using references will help me do that. The problem is: I'm still fairly new to Perl, and wading through "Intermediate Perl", and it hasn't quite clicked in my head if:
I appreciate any tips anyone can offer that might help me along.
In reply to Changing variable names in a loop by Mad_Mac
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |