ddrew78 has asked for the wisdom of the Perl Monks concerning the following question:
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.
File1File24546 4748
File3IT IT IT IT IT IT IT
918 908
What i need to get is output below:
File 918File 908SR-IT-SD4546-IBV-sw918-A SR-IT-SD4546-IBV-sw918-B SR-IT-SD4748-IBV-sw918-A SR-IT-SD4748-IBV-sw918-B
The code I am trying to use is this:SR-IT-SD4546-IBV-sw908-A SR-IT-SD4546-IBV-sw908-B SR-IT-SD4748-IBV-sw908-A SR-IT-SD4748-IBV-sw908-B
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.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);
Back to
Seekers of Perl Wisdom