NICE! That's even simpler than what I was expecting. :-D

Thanks for the help.

So, the values of the hash are a list separated by semicolons (just because I picked semicolons for the delimiter in my input text file). I need to put the list of values into an array, so I can use them to build my SQL statements. Sort of like this:

# Maybe I can do this as part of the original parsing? # Or maybe I can loop over the %config hash and convert # the scalar values to an array, and put a reference # to that array back into the hash? @inc_albums=split(/; /, $inc_albums) unless $inc_albums=~/^\s$/; @inc_genres=split(/; /, $inc_genres) unless $inc_genres=~/^\s$/; @inc_artists=split(/; /, $inc_artists) unless $inc_artists=~/^\s$/; @inc_songs=split(/; /, $inc_songs) unless $inc_songs=~/^\s$/; @exc_albums=split(/; /, $exc_albums) unless $exc_albums=~/^\s$/; @exc_genres=split(/; /, $exc_genres) unless $exc_genres=~/^\s$/; @exc_artists=split(/; /, $exc_artists) unless $exc_artists=~/^\s$/; @exc_songs=split(/; /, $exc_songs) unless $exc_songs=~/^\s$/; my $i_albumcriteria=q{(Songs.Album LIKE '%'||}.join(q{||'%' OR Songs.A +lbum LIKE '%'||},map {"?"} @inc_albums).q{||'%')} unless (scalar(@inc +_albums)==0) ; my $i_artistcriteria=q{(Songs.Artist LIKE '%'||}.join(q{||'%' OR Songs +.Artist LIKE '%'||},map {"?"} @inc_artists).q{||'%')} unless (scalar( +@inc_artists)==0); my $i_songcriteria=q{(Songs.SongTitle LIKE '%'||}.join(q{||'%' OR Song +s.SongTitle LIKE '%'||},map {"?"} @inc_songs).q{||'%')} unless (scala +r(@inc_songs)==0); my $i_genrecriteria=q{(Songs.Genre LIKE '%'||}.join(q{||'%' OR Songs.G +enre LIKE '%'||},map {"?"} @inc_genres).q{||'%')} unless (scalar(@inc +_genres)==0); my $i_ratingcriteria=qq{Songs.Rating $inc_ratings} unless length($inc_ +ratings)<2; my $i_datecriteria=qq{Songs.Year $inc_year} unless length($inc_year)<2 +;

I'm now trying to work out how to either do this while I'm parsing the input text the first time around, or by looping over the %confighash recommended by ig. I could use a little bit more help on this.

EDIT

I think I got it ...

foreach my $k (keys %config) { $config{$k}=[split(/; /, $config{$k})] unless $config{$k}=~/^\s$/; }

Thanks again for the help.


In reply to Re^2: Changing variable names in a loop by Mad_Mac
in thread Changing variable names in a loop by Mad_Mac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.