You've gone 5 years without learning hashes? Pick up a copy of Learning Perl, and work through it all the way. It will serve you well. Conceptually, you'll want to do something like this:
# first, tell perl you want a local version of a hash called filename my %filename; # put in the data for your states %filename ( state1 => "FileA.csv", state2 => "FileB.csv", state3 => "FileC.csv"); # The above statement is the same as writing the three commented lines + below. It's prefered because it's simpler, and requires less typing, + so it has lower odds for a mistake. Perhaps the lines below are clea +rer to a beginner, though... they do the same thing as the line above +. #$filename{"state1"}="FileA.csv"; #$filename{"state2"}="FileB.csv"; #$filename{"state3"}="FileC.csv"; # get your state variable somehow... say from a function called get_st +ate() $state = get_state(); $file = $filename{ $state }; # The above statement a just looks for a matching value for $state in +the hash. If it can't find one, uses the undefined value instead. It +assigns whatever value it came up with to $file. It's like writing th +e following big if statement, but again, with less repetition... # if ( $state eq "state1" ) { # $file = "FileA.csv"; # } elsif ( $state eq "state2" ) { # $file = "FileB.csv"; # } elsif ( $state eq "state3" ) { # $file = "FileC.csv"; # } else { # $file = undef(); # }

In reply to Re^2: Use Hash? Array? Still confused after all these years. by Anonymous Monk
in thread Use Hash? Array? Still confused after all these years. by hmbscully

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.