Add default system newline in Perl - linux

When I append text to a file I would like to add the correct line ending for the file: for Unix: "\n" and for Windows "\r\n". However, I could not find an easy way to do this. This was the best I could come up with:
use strict;
use warnings;
use Devel::CheckOS ();
my $fn = 'file';
open (my $fh, '<', $fn) or die "Could not open file '$fn': $!\n";
my $first_line = <$fh>;
my $len = length $first_line;
my $file_type = "undetermined";
if ($len == 1) {
$file_type = "Unix" if $first_line eq "\n";
}
if ($len >= 2) {
if (substr($first_line, $len - 1, 1) eq "\n") {
if (substr($first_line, $len - 2, 1) eq "\r") {
$file_type = "DOS";
} else {
$file_type = "Unix";
}
}
}
close $fh;
if ($file_type eq "undetermined") {
$file_type = get_system_file_type();
}
print "File type: $file_type.\n";
sub get_system_file_type {
return Devel::CheckOS::os_is('MicrosoftWindows') ? "DOS" : "Unix";
}
Is it really necessary to do all these checks? Or are there simpler ways to do this?

Use the :crlf handle, for example with use open and use if:
use if ($^O eq "MSWin32") => open qw(IO :crlf :all);
The relevant documentations:
PerlIO for the io layers. Note that this page states:
If the platform is MS-DOS like and normally does CRLF to "\n" translation for text files then the default layers are :
unix crlf
So the above code should be redundant, but that's what you're asking for.
perlvar for the $^O variable.
open for the open pragma.
if for conditional loading of modules.

Related

Perl daemon doesn't go through entire loop

I'm trying to make a program that works like a very simple server in Perl.
The program itself is meant to work as a library catalogue, giving the user options of searching for books by title or author, and borrowing or returning books. The list of books is provided in a separate file.
Basically, it's supposed to take requests (files) from "Requests" folder, process them, and then give answers (also files) in "Answers" folder. After the process is over, it deletes the old requests and repeats the process (answers are deleted by the client after they are accepted).
It's meant to run as a daemon, but for some reason only the loop responsible for deleting the request files works in the background - the requests are not processed into answers, but are just deleted. Whenever a new request appears, it's almost immediately deleted.
I'm learning to use daemons and tried to emulate what is in this thread.
#!/usr/bin/perl
use warnings;
use strict;
use Proc::Daemon;
#FUNCTIONS DEFINTIONS
sub FindAuthor
{
#try to find book by this author in the catalogue
}
sub FindTitle
{
#try to find book with this title in the catalogue
}
sub CheckIfCanBeReturned
{
#check if the book is borrowed and by whom
}
#attempt at daemonization
Proc::Daemon::Init;
my $continueWork = 1;
$SIG{TERM} = sub { $continueWork = 0 };
while ( $continueWork )
{
sleep(2);
my #RequestFilesArray = `ls /home/Ex5/Requests`;
#list all requests currently in the Request folder
for ( my $b = 0; $b < #RequestFilesArray; $b++)
{
my $cut = `printf "$RequestFilesArray[$b]" | wc -m`;
$cut = $cut - 1;
$RequestFilesArray[$b] = substr $RequestFilesArray[$b], 0, $cut;
}
#the requests are formatted in such way,
#that the first 2 letters indicate what the client wants to be done
#and the rest is taken parameters used in the processing
for (my $i = 0; $i < #RequestFilesArray; $i++)
{
my $UserRequest = `tail -1 Requests/$RequestFilesArray[$i]`;
my $fix = `printf "$UserRequest" | wc -m`;
$fix = $fix - 1;
$UserRequest = substr $UserRequest, 0, $fix;
my $RequestType = substr $UserRequest, 0, 2;
my $RequestedValue = substr $UserRequest, 3;
my $RequestNumber = $i;
if ($RequestType eq "fa")
{
#FIND BY AUTHOR
my #results = FindAuthor ($RequestedValue);
my $filename = "/home/Ex5/Answers/" . $RequestFilesArray[$RequestNumber];
open (my $answerFile, '>', $filename) or die "$!";
for (my $a = 0; $a < #results; $a++)
{
print $answerFile $results[$a],"\n";
}
close $answerFile;
}
elsif ($RequestType eq "ft")
{
#FIND BY TITLE
my #results = FindTitle ($RequestedValue);
my $filename = "/home/Ex5/Answers/" . $RequestFilesArray[$RequestNumber];
open ( my $answerFile, '>', $filename) or die "$!";
for (my $a = 0; $a < #results; $a++)
{
print $answerFile $results[$a],"\n";
}
close $answerFile;
}
elsif ($RequestType eq "br")
{
#BOOK RETURN
my $result = CheckIfCanBeReturned ($RequestedValue, $RequestFilesArray[$RequestNumber]);
my $filename = "/home/Ex5/Answers/" . $RequestFilesArray[$RequestNumber];
open ( my $answerFile, '>', $filename) or die "$!";
print $answerFile $result;
close $answerFile;
}
elsif ($RequestType eq "bb")
{
#BOOK BORROW
my $result = CheckIfCanBeBorrowed ($RequestedValue, $RequestFilesArray[$RequestNumber]);
my $filename = "/home/Ex5/Answers/" . $RequestFilesArray[$RequestNumber];
open ( my $answerFile, '>', $filename) or die "$!";
print $answerFile $result;
close $answerFile;
}
else
{
print "something went wrong with this request";
}
}
#deleting processed requests
for ( my $e = 0; $e < #RequestFilesArray; $e++)
{
my $removeReq = "/home/Ex5/Requests/" . $RequestFilesArray[$e];
unlink $removeReq;
}
#$continueWork =0;
}
You have written way too much code before attempting to test it. You have also started shell processes at every opportunity rather than learning the correct way to achieve things in Perl
The first mistake is to use ls to discover what jobs are waiting. ls prints multiple files per line, and you treat the whole of each line as a file name, using the bizarre printf "$RequestFilesArray[$b]" | wc -m instead of length $RequestFilesArray[$b]
Things only get worse after that
I suggest the following
Start again from scratch
Write your program in Perl. Perl isn't a shell language
Advance in very small increments, making sure that your code compiles and does what it is supposed to every three or four lines. It does wonders for the confidence to know that you're enhancing working code rather than creating a magical sequence of random characters
Learn how to debug. You appear to be staring at your code hoping for inspiration to strike in the manner of someone staring at their car engine in the hope of seeing why it won't start
Delete request files as part of processing the request, and only once the request has been processed and the answer file successfully written. It shouldn't be done in a separate loop
Taking what you provided, here's some pseudocode I've devised for you that you can use as somewhat of a template. This is by NO MEANS exhaustive. I think the advice #Borodin gave is sound and prudent.
This is all untested and much of the new stuff is pseudocode. However, hopefully, there are some breadcrumbs from which to learn. Also, as I stated above, your use of Proc::Daemon::Init is suspect. At the very least, it is so minimally used that it is gobbling up whatever error(s) is/are occurring and you've no idea what's wrong with the script.
#!/usr/bin/perl -wl
use strict;
use File::Basename;
use File::Spec;
use Proc::Daemon;
use Data::Dumper;
# turn off buffering
$|++;
#FUNCTIONS DEFINTIONS
sub FindAuthor
{
#try to find book by this author in the catalogue
}
sub FindTitle
{
#try to find book with this title in the catalogue
}
sub CheckIfCanBeReturned
{
#check if the book is borrowed and by whom
}
sub tail
{
my $file = shift;
# do work
}
sub find_by
{
my $file = shift;
my $val = shift;
my $by = shift;
my #results;
my $xt = 0;
# sanity check args
# do work
if ( $by eq 'author' )
{
my #results = FindByAuthor(blah);
}
elsif ( $by eq 'blah' )
{
#results = blah();
}
#...etc
# really should use File::Spec IE
my $filename = File::Spec->catfile('home', 'Ex5', 'Answers', $file);
# might be a good idea to either append or validate you're not clobbering
# an existent file here because this is currently clobbering.
open (my $answerFile, '>', $filename) or die "$!";
for ( #results )
{
print $answerFile $_,"\n";
}
close $answerFile;
# have some error checking in place and set $xt to 1 if an error occurs
return $xt;
}
#attempt at daemonization
# whatever this is is completely broken methinks.
#Proc::Daemon::Init;
my $continueWork++;
my $r_dir = '/home/user/Requests';
$SIG{TERM} = sub { $continueWork = 0 };
# going with pseudocode
while ( $continueWork )
{
#list all requests currently in the Request folder
my #RequestFilesArray = grep(/[^\.]/, <$r_dir/*>);
#the requests are formatted in such way,
#that the first 2 letters indicate what the client wants to be done
#and the rest is taken parameters used in the processing
for my $request_file ( #RequestFilesArray )
{
my $result = 0;
$request_file = basename($request_file);
my $cut = length($request_file) - 1;
my $work_on = substr $request_file, 0, $cut;
my $UserRequest = tail($request_file);
my $fix = length($UserRequest) - 1;
$UserRequest = substr $UserRequest, 0, $fix;
my $RequestType = substr $UserRequest, 0, 2;
my $RequestedValue = substr $UserRequest, 3;
if ($RequestType eq "fa")
{
#FIND BY AUTHOR
$result = find_by($request_file, $RequestedValue, 'author');
}
elsif ($RequestType eq "ft")
{
#FIND BY TITLE
$result = find_by($request_file, $RequestedValue, 'title');
}
elsif ($RequestType eq "br")
{
#BOOK RETURN
$result = CheckIfCanBeReturned ($RequestedValue, $request_file) or handle();
}
elsif ($RequestType eq "bb")
{
#BOOK BORROW
$result = CheckIfCanBeBorrowed ($RequestedValue, $request_file) or handle();
}
else
{
print STDERR "something went wrong with this request";
}
}
#deleting processed requests
if ( $result == 1 )
{
unlink $work_on;
}
sleep(2);
}
Take special note to my "mild" attempt and DRYing up your code by using the find_by subroutine. You had a LOT of duplicate code in your original script, which I moved into a single sub routine. DRY eq 'Don't Repeat Yourself'.

Trying to read a pdf, parse the data, and write desired data to spreadsheet using Perl on Linux

I am trying to extract data from credit card statements and enter it into a spreadsheet for tax purposes. What I've done so far involves multiple steps but I'm relatively new to Perl and am working from what I know. Here are two separate scripts I've written so far...one reads all data from a pdf and writes to a text file, the other parses the text (imperfectly) and writes it to another text file. Then I'd like to either create a csv file to import into a spreadsheet or write directly to a spreadsheet. I'd like to do this in one script but two or three will suffice.
first script:
#!/usr/bin/perl
use CAM::PDF;
my $file = "/home/cd/Documents/Jan14.pdf";
my $pdf = CAM::PDF->new($file);
my $doc="";
my $filename = 'report.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
for ($i=1; $i <= $pdf->numPages(); $i++) {
$doc = $doc.$pdf->getPageText($i);
}
print $fh " $doc\n";
close $fh;
print "done\n";
Second script:
#!/usr/bin/perl
use strict;
use warnings;
undef $/; # Enable 'slurp' mode
open (FILE, '<', 'report.txt') or die "Could not open report.txt: $!";
my $file = <FILE>; # Whole file here now...
my ($stuff_that_interests_me) =
($file =~ m/.*?(Date of Transaction.*?CONTINUED).*/s);
print "$stuff_that_interests_me\n";
my $filename = 'data.txt';
open(my $fh, '>>', $filename) or die "Could not open file '$filename' $!";
print $fh " $stuff_that_interests_me\n";
close $fh;
print "done\n";
close (FILE) or die "Could not close report.txt: $!";
open (FILE2, '<', 'report.txt') or die "Could not open report.txt: $!";
my $file2 = <FILE2>; # Whole file here now...
my ($other_stuff_that_interests_me) =
($file2 =~ m/.*?(Page 2 .*?TRANSACTIONS THIS CYCLE).*/s);
print "$other_stuff_that_interests_me\n";
$filename = 'data.txt';
open($fh, '>>', $filename) or die "Could not open file '$filename' $!";
print $fh " $other_stuff_that_interests_me\n";
close $fh;
print "done\n";
close (FILE2) or die "Could not close report.txt: $!";
Update:
I found a module (CAM:PDF) on CPAN that works great for what I'm trying to do...it even renders the data in a format that I can more easily use for my spreadsheet. However, I haven't yet figured out how to get it to print to a .txt file...any suggestions?
#!/usr/bin/perl -w
package main;
use warnings;
use strict;
use CAM::PDF;
use Getopt::Long;
use Pod::Usage;
use English qw(-no_match_vars);
our $VERSION = '1.60';
my %opts = (
density => undef,
xdensity => undef,
ydensity => undef,
check => 0,
renderer => 'CAM::PDF::Renderer::Dump',
verbose => 0,
help => 0,
version => 0,
);
Getopt::Long::Configure('bundling');
GetOptions('r|renderer=s' => \$opts{renderer},
'd|density=f' => \$opts{density},
'x|xdensity=f' => \$opts{xdensity},
'y|ydensity=f' => \$opts{ydensity},
'c|check' => \$opts{check},
'v|verbose' => \$opts{verbose},
'h|help' => \$opts{help},
'V|version' => \$opts{version},
) or pod2usage(1);
if ($opts{help})
{
pod2usage(-exitstatus => 0, -verbose => 2);
}
if ($opts{version})
{
print "CAM::PDF v$CAM::PDF::VERSION\n";
exit 0;
}
if (defined $opts{density})
{
$opts{xdensity} = $opts{ydensity} = $opts{density};
}
if (defined $opts{xdensity} || defined $opts{ydensity})
{
if (!eval "require $opts{renderer}") ## no critic (StringyEval)
{
die $EVAL_ERROR;
}
if (defined $opts{xdensity})
{
no strict 'refs'; ## no critic(ProhibitNoStrict)
my $varname = $opts{renderer}.'::xdensity';
${$varname} = $opts{xdensity};
}
if (defined $opts{ydensity})
{
no strict 'refs'; ## no critic(ProhibitNoStrict)
my $varname = $opts{renderer}.'::ydensity';
${$varname} = $opts{ydensity};
}
}
if (#ARGV < 1)
{
pod2usage(1);
}
my $file = shift;
my $pagelist = shift;
my $doc = CAM::PDF->new($file) || die "$CAM::PDF::errstr\n";
foreach my $p ($doc->rangeToArray(1, $doc->numPages(), $pagelist))
{
my $tree = $doc->getPageContentTree($p, $opts{verbose});
if ($opts{check})
{
print "Checking page $p\n";
if (!$tree->validate())
{
print " Failed\n";
}
}
$tree->render($opts{renderer});
}
I'd like to either create a csv file to import into a spreadsheet or
write directly to a spreadsheet.
You can write directly to the spreadsheet, check out Excel::Writer::XLSX.
If you want to create a CSV file then you can try using Text::CSV and Text::CSV_XS.

I can print to file using > in terminal but how do I print to files where I create the name using a $ in this code

I can print to file using > in terminal but how do I print to files where I create the name using a $ in this code?
use strict;
use warnings;
my $calls_dir = "Ask/";
opendir(my $search_dir, $calls_dir) or die "$!\n";
my #files = grep /\.txt$/i, readdir $search_dir;
closedir $search_dir;
print "Got ", scalar #files, " files\n";
#my %seen = ();
foreach my $file (#files) {
my %seen = ();
my $current_file = $calls_dir . $file;
open my $FILE, '<', $current_file or die "$file: $!\n";
while (<$FILE>) {
#if (/phone/i) {
chomp;
#if (/phone\s*(.*)\r?$/i) {
#if (/^phone\s*:\s*(.*)\r?$/i) {
#if (/Contact\s*(.*)\r?$/i) {
if (/^*(.*)Contact\s*(.*)\r?$/i) {
$seen{$1} = 1;
print $file."\t"."$_\n";# I want to print this line to file named $file."result".txt
#print "\t";
#print "\n";
#print "$_\n";
#print "\t";
#print "\n";
foreach my $addr ( sort keys %seen ) {
...
}
}
}
close $FILE;
}
Open a filehandle for writing to that file and print to it. If it doesn't exist, Perl will create it.
open my $fh, '>', "${file}result.txt" or die $!;
$fh->print("$file\t$_\n");
From perldoc -f open:
If MODE is ">", the file is opened for
output, with existing files first being truncated ("clobbered")
and nonexisting files newly created. If MODE is ">>", the file is
opened for appending, again being created if necessary.
If you want to avoid truncation, check if it exists first using -e and/or add something to the filename to make it reasonably unique (like a Unix timestamp).

How to read "<somestring>" in input string in perl

Below is my code. It still produces same string with no "<init>"
input string :
1: invokespecial #1 // Method java/lang/Object."<init>":()V
my $file = "Hello.javap";
open my $fh, '<', $file or die "Could not open '$file' $!";
while (my $line = <$fh>) {
if (index(uc($line), uc("Code:")) != -1) {
$code_block_started=1;
}
if(index($line,":")==-1)
{
if (my ($method) = $line =~ /.* \/\/ Method (.*);/) {
print "Method: $method\n";
}
print $line;
$code_block_started=0;
}
if($code_block_started){
if ($line =~/[0-9]/) {
my #num_strip = split(':',$line);
my #get_command = split(' ',$num_strip[1]);
# print "\n $get_command[0]";
$count{$get_command[0]}++;
}
}
Are you simply asking how to escape the " in perl? If so, write \"<init>\" just like in most languages.
Are you asking for a regular expression? If so, $str ~= /.* \/\/ Method (.*);/ will put java/lang/Object."<init>":()V into $1.
while (my $str = <>) {
if (my ($method) = $str =~ m{// Method (.*)}) {
print "$method\n";
}
}
when Perl sees the double-quote just before the word "name" it thinks that was the end of the string and then it complains about the word name being a bareword.
You might have already guessed, we need to escape the embedded " character:
use strict;
use warnings;
my $name = 'foo';
print "The \"name\" is \"$name\"\n";
http://perlmaven.com/quoted-interpolated-and-escaped-strings-in-perl

perl : String extraction based on pattern match [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
A file FILE1 has several thousands of lines with a terminating pattern _Pattern1.
A second file too has several thousands of lines with the same terminating pattern _Pattern1.
I must now:
Read FILE1 line by line
Find out if the line has any string terminating with _Pattern1
Extract the string and store it into a variable
Open FILE2 and read it line by line
Find out if the line just read from FILE2 contains the string stored in the variable above
How is this to be done in perl?
EDIT2:
Allright, with a bit of googling and referring to the links enlisted below, I solved my problem.
Here is the code snippet.
#!/usr/bin/perl
use strict;
use warnings;
my $OriginalHeader=$ARGV[0]; ## Source file
my $GeneratedHeader=$ARGV[1];## File to compare against
my $DeltaHeader=$ARGV[2]; ## File to store misses
my $MatchingPattern="_Pos";
my $FoundPattern;
open FILE1, $OriginalHeader or die $!;
open FILE2, $GeneratedHeader or die $!;
open (FILE3, ">$DeltaHeader") or die $!;
my $lineFromOriginalHeader;
my $lineFromGeneratedHeader;
my $TotalMacrosExamined = 0;
my $TotalMacrosMissed = 0;
while($lineFromOriginalHeader=<FILE1>)
{
if($lineFromOriginalHeader =~ /$MatchingPattern/)
{
my $index = index($lineFromOriginalHeader,$MatchingPattern);
my $BackIndex = $index;
my $BackIndexStart = $index;
$BackIndex = $BackIndex - 1;
## Use this while loop to extract the substring.
while (1)
{
my $ExtractedChar = substr($lineFromOriginalHeader,$BackIndex,1);
if ($ExtractedChar =~ / /)
{
$FoundPattern = substr($lineFromOriginalHeader,$BackIndex + 1,$BackIndexStart + 3 -
$BackIndex);
print "Identified $FoundPattern \n";
$TotalMacrosExamined = $TotalMacrosExamined + 1;
##Skip the next line
$lineFromOriginalHeader = <FILE1>;
last;
}
else
{
$BackIndex = $BackIndex - 1;
}
} ##while(1)
## We now look for $FoundPattern in FILE2
while ($lineFromGeneratedHeader = <FILE2>)
{
if (index($lineFromGeneratedHeader,$FoundPattern)!= -1)
{
##Pattern found. Reset file pointer and break out of while loop
seek FILE2,0,0;
last;
}
else
{
if (eof(FILE2) == 1)
{
print FILE3 "Generated header misses $FoundPattern\n";
$TotalMacrosMissed = $TotalMacrosMissed + 1;
seek FILE2,0,0;
last;
}
}
} ##while(1)
}
else
{
##NOP
}
} ##while (linefromoriginalheader)
close FILE1;
close FILE2;
close FILE3;
print "Total number of bitfields examined = $TotalMacrosExamined\n";
print "Number of macros obsolete = $TotalMacrosMissed\n";
Just a first cut at making your code more Perly. Actually plenty more could be done, including $some_var is usually used vs $SomeVar in Perl, but I didn't get that far.
#!/usr/bin/perl
use strict;
use warnings;
my ($OriginalHeader, $GeneratedHeader, $DeltaHeader) = #ARGV;
my $MatchingPattern=qr/(\S*_Pos)/; # all non-whitespace terminated by _Pos
open my $file1, '<', $OriginalHeader or die $!;
open my $file2, '<', $GeneratedHeader or die $!;
open my $file3, '>', $DeltaHeader or die $!;
my $TotalMacrosExamined = 0;
my $TotalMacrosMissed = 0;
while(my $lineFromOriginalHeader=<$file1>) {
next unless $lineFromOriginalHeader =~ $MatchingPattern;
my $FoundPattern = $1; # matched string
print "Identified $FoundPattern \n";
$TotalMacrosExamined++;
##Skip the next line
<$file1>;
## We now look for $FoundPattern in FILE2
my $match_found = 0;
while (my $lineFromGeneratedHeader = <$file2>) {
if (index($lineFromGeneratedHeader,$FoundPattern)!= -1) {
##Pattern found. Close the file and break out of while loop
$match_found++;
last;
}
}
unless ($match_found) {
print $file3 "Generated header misses $FoundPattern\n";
$TotalMacrosMissed++;
}
seek $file2,0,0;
}
print "Total number of bitfields examined = $TotalMacrosExamined\n";
print "Number of macros obsolete = $TotalMacrosMissed\n";
Having programmed in C all my life, I googled usage of the perl constructs below and wrote a C like program. This works flawlessly for me. :-)
Edit : This is to clarify why I must skip a line in the algo below. The pattern which is retrieved and later searched for in the second file occurs on two consecutive lines. It therefore suffices that its first occurence is reliably detected. Also a nitpick, It is always guaranteed that the substring containing the pattern is always the second substring on the line.
e.g #define Something_Pos (Some Value)
#!/usr/bin/perl
use strict;
use warnings;
my $OriginalHeader=$ARGV[0];
my $GeneratedHeader=$ARGV[1];
my $DeltaHeader=$ARGV[2];
my $MatchingPattern="_Pos";
my $FoundPattern;
open FILE1, $OriginalHeader or die $!;
open FILE2, $GeneratedHeader or die $!;
open (FILE3, ">$DeltaHeader") or die $!;
my $lineFromOriginalHeader;
my $lineFromGeneratedHeader;
my $TotalMacrosExamined = 0;
my $TotalMacrosMissed = 0;
while($lineFromOriginalHeader=<FILE1>)
{
if($lineFromOriginalHeader =~ /$MatchingPattern/)
{
my $index = index($lineFromOriginalHeader,$MatchingPattern);
my $BackIndex = $index;
my $BackIndexStart = $index;
$BackIndex = $BackIndex - 1;
## Use this while loop to extract the substring.
while (1)
{
my $ExtractedChar = substr($lineFromOriginalHeader,$BackIndex,1);
if ($ExtractedChar =~ / /)
{
$FoundPattern = substr($lineFromOriginalHeader,$BackIndex + 1,$BackIndexStart + 3 -
$BackIndex);
print "Identified $FoundPattern \n";
$TotalMacrosExamined = $TotalMacrosExamined + 1;
##Skip the next line
$lineFromOriginalHeader = <FILE1>;
last;
}
else
{
$BackIndex = $BackIndex - 1;
}
} ##while(1)
## We now look for $FoundPattern in FILE2
while ($lineFromGeneratedHeader = <FILE2>)
{
##print "Read the following line from FILE2: $lineFromGeneratedHeader\n";
if (index($lineFromGeneratedHeader,$FoundPattern)!= -1)
{
##Pattern found. Close the file and break out of while loop
seek FILE2,0,0;
last;
}
else
{
if (eof(FILE2) == 1)
{
print FILE3 "Generated header misses $FoundPattern\n";
$TotalMacrosMissed = $TotalMacrosMissed + 1;
seek FILE2,0,0;
last;
}
}
} ##while(1)
}
else
{
}
} ##while (linefromoriginalheader)
close FILE1;
close FILE2;
close FILE3;
print "Total number of bitfields examined = $TotalMacrosExamined\n";
print "Number of macros obsolete = $TotalMacrosMissed\n";

Resources