Hi Jonathan,
Tks for your advice.
- snip -
: You can always define a sub called print2 (untested, and I've been doing numerical analysis all evening, nothing seems quite the same now)...
:
:
sub print2 {
: print @_;
: print FILE @_;
: }
:
: Then you can do:-
:
: open FILE, ">$file" or die "Can't open $file for output: $!\n";
:
: Where you'd have put print before, you put:-
:
: print2 "stuff";
:
: And it prints to the console and the file. Then at the end you just:-
:
: close FILE;
- snip -
Test performed but failed.
"Print to file" OK
but
"Print on Console" failed
Printout on Console:-
$ perl compare_s2_02.pl NewCompare doc_a.txt doc_b.txt
REMARK :
OLINENO=Old Line No. NLINENO=New Line No.
OWORDNO=Old Word No. NWORDNO=New Word No.
File: NewCompare_satimis_2004.11.19.01:03.txt
Filehandle FILE opened only for input at compare_s2_pravin02test.pl line 73.
stuff
- END -
Script :-
#!/opt/bin/perl -w
use strict;
use warnings;
use POSIX qw(strftime);
use Term::ANSIColor qw(:constants);
print "\n";
print BOLD WHITE ON_MAGENTA "REMARK :", RESET "\n";
print RED "OLINENO=Old Line No. NLINENO=New Line No.", RESET "\n";
print RED "OWORDNO=Old Word No. NWORDNO=New Word No.", RESET "\n\n";
chomp (my $file=$ARGV[0]);
chomp (my $user=`whoami`);
my $now = strftime "%Y.%m.%d.%R", localtime;
$file="$ARGV[0]_${user}_${now}.txt";
my ($org, $mis, $lno1, $wno, $lno2, $wno1);
print "File: $file \n";
format FILE_TOP=
ORGINAL MISTAKE OLINENO OWORDNO NLINENO NWORDNO
.
format FILE=
@<<<<<<<<<< @<<<<<<<<<< @## @## @## @##
$org, $mis, $lno1, $wno, $lno2, $wno1
.
my $orgfile='doc_a.txt';
open(INFO,$orgfile) || die "Cannot open $orgfile: $!";
my @basedoc=<INFO>;
close(INFO);
my $typfile='doc_b.txt';
open(INFO1,$typfile) || die "Cannot open $typfile: $!";
my @typedoc=<INFO1>;
close(INFO1);
open FILE, ">$file" or die "Can't open $file for output: $!\n";
my $lno=0;
$wno=0;
foreach my $i (@typedoc) {
my $incr=0;
my @typedoc1=split(/ /,$i);
my @basedoc1=split(/ /,$basedoc[$lno]);
foreach my $k (@typedoc1){
my $var=$basedoc1[$incr];
if ( $var ne $k ){
$org=$var;
$mis=$k;
$wno=$incr+1;
$lno1=$lno+1;
$wno1=$incr+1;
$lno2=$lno+1;
#$~="FILE_MID";
write FILE;
}
$incr++;
}
$lno++;
}
sub print2 {
print @_;
print FILE @_;
}
open FILE, "<$file" or die "Can't open $file for output: $!\n";
print2 "stuff";
close FILE;
print "\n";
- END of SCRIPT -
Any suggestion to fix the problem? TIA
B.R.
satimis