Greetings:
I am working on a script that updates some files for user access on a propritory system. Basically, I need to update 12 files based on some very weird logic.
The English version is as follows: for fileset 1, append file with user string. for fileset 2, append file with user string. these are always done together if developer access. for fileset 3, append file with user string, only if production access. Fileset four is appended with user string, and is different from filesets 1 - 3. if filesets 1 - 3 are appended, push script must be run, if fileset 4 no push.
above is highly simplified from the real situation but the 'user strings' mentioned differ. There are four databases that are used, I will call them db1, db2, db3 and db4 for my code. So the jist of what I tried is a nested loop. I am having trouble with the second part of the developer access. Basically, it needs to run an outer loop for all three instances. But if Production is not needed, the loop should terminate. This is done inside another "master loop" that does this foreach user in an input file. I also set a flag variable to try to make this work.
Code I tried (not complete script):if($access eq 'prod' || $access eq 'dev') { if($access eq 'dev') { $flag = "dev"; } for(my $i = 0; $i < 3;$i++) { if($flag eq 'dev') { @files = ('file1', 'file2', 'file3', 'file4'); } elsif($i == 2) { $flag = "reporting"; @files = ('file1', 'file2', 'file3', 'file4'); } if($access eq 'prod') { $flag = "prod"; @files = ('file1', 'file2', 'file3', 'file4'); } else { break; } for (my $j = 0; $j < 4; $j++) { my $file = $files[$j]; my $db = $dbs[$j]; print("j variable is: $j\n"); $acString = &build_string($user, $db, $flag); &WriteFile($file, $acString); } } }
The build string sub puts the string to append to the file together (first run through inner loop is db1). Then it calls the writefile sub and appends the string to the file that is passed in from the fileset (@files).
Again, this is done for however many users are read in from an input file which is ARGV[0].
Hope someone can help me sort this out. Thanks in advance for the help all!
In reply to Logic Issues with conditionals by jmneedhamco
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |