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

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.