I believe it's hard because it either clicks in your head or not. Well at least it's case with me - once I was introduced to hashes I simply got them as granted.
As someone pointed out - you use hashes for storing any data that has names. Such as database tables and forms. Sometimes it's also good to use hash as a parameter for some function/method (often referred as PARAMHASH). In cases when you have more than few parameters.
Anyway if I understood you - I would use following:
- hash for storing the form data > you get it from CGI that way
- hash for storing file names. As keys you have state options, and as matching values you have file names.
So it ends up with something like:
my $request = CGI->new(); # Is it a hashref or plain hash ?!? my $values = $request->Vars(); # Or maybe coming from a config file my %files = { state1 => 'filename1.csv', state2 => 'filename2.csv', default => 'default_filename.csv', } my $file_name = $files{default}; if(defined $files{$values{state}}) { $file_name = $files{$values{state}; } # Or something shorter like : # my $file_name = $files{$values{state}} || $files{default}; #open....
In reply to Re: Use Hash? Array? Still confused after all these years.
by techcode
in thread Use Hash? Array? Still confused after all these years.
by hmbscully
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |