Reputation: 3
I have a Perl script (I didn't write it) that takes a POST from an html page and it displays a certain section of a txt file to a webpage. The problem is, now I need it to also make a text file of that section to a text file on our Unix server. Any help? Code below.
#!/usr/bin/perl
#
print "Content-type: text/html\n\n";
print '<pre>';
read(STDIN, $buf, $ENV{'CONTENT_LENGTH'});
#print "$buf\n";
#print "$REMOTE_USER = $REMOTE_USER\n";
@pairs = split(/&/, $buf);
#print "$pairs\n";
($txt_HRcode, $lc_HRcode) = split(/=/,$pairs[0]);
#print "$txt_HRcode\n";
#$HRcode = " HRcode: E2PSYAA0";
$HRcode = " HRcode: F8".uc($lc_HRcode)."0";
#print "$HRcode\n";
open(LINEFIND, "grep -n \"$HRcode\" /release/ucpmr/ucpmr.txt |") or die print "Can't Open File" ;
$line_num = <LINEFIND>;
#print "$line_num\n";
#if($line_num !~ m/$HRcode/) {print "SEQUENCE CODE NOT FOUND"; die()};
($sline, $hrd, $lin_text) = split(/:/, $line_num);
$beg_line = ($sline - 2);
$end_line = ($beg_line + 10000);
#print "$beg_line\n";
#print "$end_line\n";
close(LINEFIND);
open(DISP, "/release/ucpmr/ucpmr.txt") or die print "File is no longer in History. Press Back to Return";
for($incr=1; $incr <= $end_line; $incr +=1)
{$line = <DISP>;
if($incr > $beg_line) {
if($incr >$sline){
if($line =~ m/HRcode: F8/){
if($line !~ m/$HRcode/) {$quit_line = $incr-3 ; last;
close(DISP);}}}}}
open(PRINTFIND, "/release/ucpmr/ucpmr.txt") or die print "File is no longer in History. Press Back to Return";
for($incr=1; $incr <= $quit_line; $incr +=1)
{$line = <PRINTFIND>;
#$line =~ s/\d\d\d-\d\d-/XXX-XX-/;
if($incr > $beg_line) {print"$line";}}
#print "quit line is : $quit_line\n";
print "</pre>";
Upvotes: 0
Views: 90
Reputation: 124646
Change the end part, starting from open(PRINTFIND, ...
like this:
open(PRINTFIND, "/release/ucpmr/ucpmr.txt") or die print "File is no longer in History. Press Back to Return";
open(my $fh, '>/release/ucpmr/TEXT_FILE_NAME.txt');
for($incr=1; $incr <= $quit_line; $incr +=1)
{$line = <PRINTFIND>;
#$line =~ s/\d\d\d-\d\d-/XXX-XX-/;
if($incr > $beg_line) {print"$line"; print $fh $line; }}
#print "quit line is : $quit_line\n";
print "</pre>";
... but dude, if you're a .NET guy, do yourself a favor and rewrite this mess in .NET, seriously...
Upvotes: 1
Reputation: 1401
open(my $fh, '>', '/release/ucpmr/TEXT_FILE_NAME.txt');
print $fh FILE_CONTENT;
close $fh;
like this?
Upvotes: 0