Madam has asked for the wisdom of the Perl Monks concerning the following question:
my $flag = 1; if ( -e $file1 ) { print "Script '$file1' already exists\n"; open(FILE1,"$file1"); my @seq1 = <FILE1>; close FILE1; # @seq2 contains the contents of the file to generated. my $diff = Algorithm::Diff->new( \@seq1, \@seq2 ); my $sep; my $flag = 1; $diff->Base( 1 ); # Return line numbers, not indices while( $diff->Next() ) { next if $diff->Same(); if( ! $diff->Items(2) || ! $diff->Items(1) ) { $flag = 0; print $diff->Get(qw( Min1 Max1 Max2 )),"\n"; } else { $flag = 0; $sep = "---\n"; print $diff->Get(qw( Min1 Max1 Min2 Max2 )),"\n"; } print "< $_" for $diff->Items(1); print $sep; print "> $_" for $diff->Items(2); } if($flag == 0) { print "User edits,do u want to overwrite the exisiting $file1?"; print "[INFO] Continue ? [no]"; my $answer = <STDIN> ; chomp $answer; if ($answer =~ /^n/i) { print"Not Generated the script '$file1'"; } ....
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: existing file is modified or not
by tachyon (Chancellor) on Nov 25, 2004 at 08:37 UTC | |
Re: existing file is modified or not
by rupesh (Hermit) on Nov 25, 2004 at 09:44 UTC | |
Re: existing file is modified or not
by rev_1318 (Chaplain) on Nov 25, 2004 at 10:42 UTC | |
by steves (Curate) on Nov 25, 2004 at 13:25 UTC |