Dear Most Merciful and Benevolent Monks,
I come with utter supplication and freely admit my utter ignorance and sloth. I plead with you to have extreme mercy and patience so as to accept my most basic request.
I have a text file called funtime.dat that is comma separated values. Here is a small snippet:
IM,BEN01,D,0 IM,BEN02,D,0 IM,BEN03, ,0 IM,BEN04, ,0 IM,BEN05, ,0 IM,BEN06,C,0 IM,BEN07, ,0 IM,BEN08, ,0 IM,BEN09, ,0 IM,BEN10,D,0
My Perl code is thus and works with the following output included below:
#!/usr/bin/perl open(MYINPUTFILE, "<funtime.dat"); while(<MYINPUTFILE>) { my($line) = $_; chomp($line); @data = split(/,/, $line); if ((@data[2] eq "D")||(@data[2] eq "C")) { printf ("\n type "); print @data[2]." "; print @data[1].".txt "; } else { print @data[1].".txt "; } } close(MYINPUTFILE);
My output is
type D BEN01.txt type D BEN02.txt BEN03.txt BEN04.txt BEN05.txt type C BEN06.txt BEN07.txt BEN08.txt BEN09.txt type D BEN10.txt
type D BEN01.txt > BEN01.txt type D BEN02.txt BEN03.txt BEN04.txt BEN05.txt >BEN02.txt type C BEN06.txt BEN07.txt BEN08.txt BEN09.txt > BEN06.txt type D BEN10.txt > BEN10.txt
Please disregard the C and D as those I use for debugging purposes. Obviously I would then pipe the output of the perl program into a .BAT program which I would execute in MS-DOS.
I believe I should be using some global values instead of local values or something along those lines. In terms of when the value of the line is a "D" or a "C", it gets text file stored as a value until another "D" or "C" value is read and then it prints out a "> textfile.txt" and the makes a newline and prints out "type" and so on.
If this is too difficult how about using the last file before the document has a "D" or "C" to pipe it out to such as this following example:
type D BEN01.txt > BEN01.txt type D BEN02.txt BEN03.txt BEN04.txt BEN05.txt > BEN05.txt type C BEN06.txt BEN07.txt BEN08.txt BEN09.txt >BEN09.txt type D BEN10.txt > BEN10.txt
You might ask why don't I just concatenate the files in Perl. The thing is I am getting the .dat file and therefore it is an extra step. These .dat files can actually be 1,000,000+ lines so that is why I am using Perl to automate this process.
Thank you so much for your assistance.
In reply to Global vs. Local Variables Assistance Requested by Knoperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |