Mad_Mac has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Changing variable names in a loop
by morgon (Priest) on Oct 15, 2010 at 19:56 UTC | |
by eyepopslikeamosquito (Archbishop) on Oct 15, 2010 at 20:20 UTC | |
by morgon (Priest) on Oct 16, 2010 at 13:19 UTC | |
by eyepopslikeamosquito (Archbishop) on Oct 16, 2010 at 21:05 UTC | |
|
Re: Changing variable names in a loop
by ig (Vicar) on Oct 15, 2010 at 21:06 UTC | |
by Mad_Mac (Beadle) on Oct 16, 2010 at 09:45 UTC | |
by ig (Vicar) on Oct 16, 2010 at 20:42 UTC | |
|
Re: Changing variable names in a loop
by superfrink (Curate) on Oct 15, 2010 at 20:02 UTC |