Dear Monks,

I have a very confusing issue. What I have is a file with anywhere from 1-7 lines in it. What I need to do is print several lines to a new file based on each line in that file. Further, the contents of the new file need to be based on input from another file, and I need that second file to be processed completely for every line in the first file. Hope this makes sense. Below is the code I currently have. It works fine for the first line in file1, but not for subsequent lines.

File1
4546 4748
File2
IT IT IT IT IT IT IT
File3
918 908

What i need to get is output below:

File 918
SR-IT-SD4546-IBV-sw918-A SR-IT-SD4546-IBV-sw918-B SR-IT-SD4748-IBV-sw918-A SR-IT-SD4748-IBV-sw918-B
File 908
SR-IT-SD4546-IBV-sw908-A SR-IT-SD4546-IBV-sw908-B SR-IT-SD4748-IBV-sw908-A SR-IT-SD4748-IBV-sw908-B
The code I am trying to use is this:
open(MYINPUTFILE, "File1"); open(MYINPUTFILE1, "File2"); open(MYINPUTFILE2, "File3"); open(HOST, ">host"); open(HOST1, ">host1"); while (<MYINPUTFILE>) { my($line) = $_; chomp($line); for ($numsw = $swnum; $numsw > 0 ; $numsw-- ){ my $line1 = <MYINPUTFILE1>; chomp($line1); my $line2 = <MYINPUTFILE2>; chomp($line2); print HOST "SR-$line1-SD$line-IBV-sw$line2-A\n"; print HOST1 "SR-$line1-SD$line-IBV-sw$line2-B\n"; open (OUTHANDLE, ">>$line2"); print OUTHANDLE "SR-$line1-SD$line-IBV-sw$line2-A\n"; print OUTHANDLE "SR-$line1-SD$line-IBV-sw$line2-B\n"; close (OUTHANDLE"); } } close (MYINPUTFILE); close (MYINPUTFILE1); close (MYINPUTFILE2); close (HOST); close (HOST1);
As you can tell, some of the output filenames are also based on the variable input. I am not very experienced with Perl, so any suggestions would be appreciated to the highest levels.

In reply to running multiple loops by ddrew78

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.