Hello Oh Masters of Perl Wisdom,
I need a script that reads in a text file, replaces the first line and outputs another file with the new first line along with the rest of the file. In the first line I need to write out a a 6 character string that is always on the 12th line of the file at the 50th position. Here is the code I have that does everything but get that 6 character variable. I wrote some other code to get the variable, but I can't seem to get the script to loop back to the top to start writing out the whole file. I want the 6 character variable to go where the 'JF' literal goes on the $newjob line in this code...
{
$buffer = '';
$filename = '';
$line = '';
$job = '';
$temp = '';
$index_job = 0;
$key = '';
$tray = '';
print LOG "$mday$mon$year $hour:$min:$sec Processing Data file, s
+plitting Jobs.\n";
# Skip first line.
#<INFILE>;
while (<INFILE>) {
$line = $_;
if ($line =~ /^(\^JOB.*)\n$/i) #if the current line is a ^job
+line then
{
$tmp = $1; #Set $tmp equal to what is in (\^JOB.*) ie: ^jo
+b PATIENTLBL -c1 -zDP7P
@pieces = split(/ /, $tmp); #Split-up the entire line, on
+spaces, into @pieces
$newjob = $pieces[0]." "."JF".$pieces[1]." ".$pieces[2]."
+".$pieces[3]."\n"; #Rebuild ^job line with JF in front of jobname
#print "newjob : ".$newjob;
$temp = $newjob; #Assign new ^job line to $temp to create
+new file(s)
if ($buffer ne "") #Not first job
{
print LOG "$mday$mon$year $hour:$min:$sec Found: $jo
+b";
$buffer_job[$index_job++] = $buffer;
}
$job = $temp;
$buffer = $temp;
}else{
$buffer .= $line;
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.