I'm new to perl. And I'm writing this script which should fetch any kind of changes that are recorded for a particular table in database from the log file containing a complete log of changes. And these changes in the particular table should be stored in a new file (for now I'm stroing in .txt file but in real have to show in browser, but thats next step).
So my problem is that the output is getting stored as I wish but all the spaces are missing and thus the output is appearing as one string with no spaces. Can anyone help out? HOW SHOULD I BRING THE SPACES BETWEEN WORDS?
Also on debugging I found that(according to me I mean) this is happening because of "while(<@file>)" as this line is taking whole file as one string with no spaces. so can anyone suggest some substitute or solution for this.
The Script is:
#!/usr/bin/perl -w
use strict;
use warnings;
#take the file as input, (if want from command line use ARGV[0])
open(FILE, "</home/apareek/sample.txt") or die '\nfile not opened $!\n';
open(my $out, ">/home/apareek/output.txt") or die ":P :P";
my $line;
my @file = <FILE>;
#take table name as input
print "\nEnter the table name you want to make query for\n";
my $tbl_name = <STDIN>;
chomp($tbl_name);
my $new_tabname = $tbl_name . "...";
print "\nTable Name: $new_tabname\n";
if (grep(m/$new_tabname/, @file) eq 1) {
print "Table name exsts.\n";
while(<@file>) {
if (/^$tbl_name/ .. /^Check/) {
if($_ !~ /$new_tabname/ and $_ !~ /Checking/) {
print $out $_; # $out (is the handler of output file)
}
}
}
}
Input Data:
Checking table BOARD_EQSL34V...
Checking table CFMGlobalTbl...
Checking table CFMMaTable...
!!!!!! Diff001: differences in record definition section
!!!!!! mdIdx : Record definition type differs Unsigned Int(4 Byte)(db1) vs. (db2)
Checking table CFMMdTable...
!!!!!! Diff002: differences in record definition section
!!!!!! mdIdx : Record definition type differs : Unsigned Int (4 Byte) (db1) vs. (db2)
Checking table CFMMepListTbl...
Checking table CFMMepTable...