in reply to Logic Issues with conditionals

I'd cleanup your @files assignments via the use of a hash. Something like this:

my %files = ( dev => [qw(dev_file1 dev_file2 dev_file3 dev_file4)], prod => [qw(prod_file1 prod_file2 prod_file3 prod_file4)], report => [qw(report_file1 report_file2 report_file3 report_file4) +], ); my $files = $files{$access};

I might even extend it to be a dispatch table, but you haven't provided enough info to say if that would be a good approach in your case.

Replies are listed 'Best First'.
Re^2: Logic Issues with conditionals
by jmneedhamco (Novice) on Mar 27, 2015 at 19:11 UTC

    thanks for the input Fishmonger! I decided this will be the way to go. I am just having one issue as I am not very familar with hashes at all. Been doing Perl things for quite a while, but hashes or key-value pairs never crossed my mind as a hash of arrays.

    that said, I figured out how to get the access part or key out of the hash, but I need to now address the elements of the arrays. For example: If I pull the keys into an array, then I can address them. Maybe there is a more direct way, and that would be nice too. But I also need to figure out how to get say element 0 from the dev array. Help is appreciated!

    my %files = ( dev => [qw(testd.txt testd1.txt testd2.txt testd3.txt)], prod => [qw(testp.txt testp1.txt testp2.txt testp3.txt)], report => [qw(testr.txt testr1.txt testr2.txt testr3.txt)], qptool => [qw(testq.txt testq1.txt testq2.txt testq3.txt)], ); @flags = keys %files;

    This gets the keys from the hash.

      There are multiple ways to access the array elements. The most direct would be:

      my %files = ( dev => [qw(dev_file1 dev_file2 dev_file3 dev_file4)], prod => [qw(prod_file1 prod_file2 prod_file3 prod_file4)], report => [qw(report_file1 report_file2 report_file3 report_file4) +], ); print $files{dev}[0];

      or you could do this

      my @dev = @{ $files{dev} }; print $dev[0];