Manjunath H N wrote:
> Hello All,
>
> The program prog.pl I have attached needs to read data from
> PurchaseRequestDataFile.txt & chomp the contents & append it with new Record
> count, But I am not able to chomp the contents, it is just appending the
> Record count to the end of the file.
This should be closer:
#!/usr/bin/perl
use strict;
use Fcntl qw(:DEFAULT :flock);
my $HAS_FLOCK => eval { flock STDOUT, 0; 1; };
my $PurchaseRequestDataFile = "/home/manjunath/PurchaseRequestDataFile.txt";
$PurchaseRequestDataFile = "data.txt";
sysopen PURDBFILE, $PurchaseRequestDataFile, O_RDWR|O_CREAT or die "open: $!";
flock PURDBFILE, LOCK_EX if $HAS_FLOCK;
my $Header = <PURDBFILE>;
chomp $Header;
if (not ($Header eq "PR#FMOARGMI%C")) {
print <<'EOD';
<html><body>
The data base file format is not valid!!
<BR>Report this error to <a href="mailto:[EMAIL PROTECTED]">Administrator</a>
</body>html>
EOD
exit 1;
}
# get record count and increment
my $RecordCount = <PURDBFILE>;
chomp $RecordCount;
$RecordCount =~ tr/#*//d;
$RecordCount++;
my $RecordCountLine = "###**###${RecordCount}***##***\n";
# rewind and write header and record count
seek PURDBFILE, 0, 0 or die "seek: $!";
print PURDBFILE "$Header\n";
print PURDBFILE $RecordCountLine;
close PURDBFILE;
print <<EOD;
<html><body>
Record count updated to $RecordCount.
</body>html>
EOD
exit;
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (Free site for Perl/Lakers)
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs