hi,
thanku for your help. I need some more help with the perl scripting.
i have to write a script which compares two files. now thw files have the data like
File1:-
.title 'title:VDDL_switched.meas0'
max_rush_current = -5.4316e-02 at = 4.9415e-09
powerup_time_u_switch_ring/u2_hs65_ls_sw3l60 = 6.3951e-09 targ = 6.9051e-09 trig = 5.1000e-10
temper = 2.5000e+01
alter# = 1.0000e+00

File2:-
.title 'title:VDDL_switched.meas0'
max_rush_current = -5.5516e-02 at = 4.9415e-09
pg_cell = 6.3977e-09 targ = 6.9066e-09 trig = 5.1000e-10
temper = 2.5230e+01
alter# = 1.1111e+00

now i have to compare this two files and check whther the value change is within 1% of the initial value.

Plz help me. i have no idea where to start with and what to do!!!

Regards
Nisha.

Like anyone here is supposed to understand your vague requirements? How come you have no idea where to start?

...
now i have to compare this two files

Use File::Compare module to compare two files or contents of two files. Go through the help doc. of this module, first and try.

and check whether the value change is within 1% of the initial value. ...

Without knowing what values you want to compare and how to calculate percentage and check whether it is greater or less than some percentage, you will never solve your problem.

First get clear with your question and dont post to clear it here. Just go through your own post see does it makes sense to you first. Or your post is just incomplete*.

katharnakh.

File::Compare does not do this type of comparing it just tells if files are the same or not the same.

File::Compare does not do this type of comparing it just tells if files are the same or not the same.

There is a compare_text() method which compares lines of two files. It takes two filehandles and a reference to subroutine. In that sub-routine we can define how we want the comparison, i.e, overriding the default comparison behavior of that method. Following is simple eg.

file1.txt

this is first line1
this is second line
this is third line1

file2.txt

this is first line2
this is second line2
this is third line2
use strict;
use warnings;
use File::Compare;
use FileHandle;

my $fh1 = FileHandle->new("file1.txt");
my $fh2 = FileHandle->new("file2.txt");

#print compare($fh1, $fh2);

# Return 0 if lines from two files end with a number, 1 otherwise
my $coderef = sub {
	my ($fline, $sline) = @_;
	return ( ( ($fline =~ /\d$/) and ($sline =~ /\d$/) ) ? 0 : 1	);
};

if ( File::Compare::compare_text($fh1, $fh2, $coderef) == 0){ print "Files compared successfully"; }
else{	print "Files does not compare";	}

$fh1->close();
$fh2->close();

katharnakh.

Yes, but it still does the same thing, it only tells you if the files (or in this case the lines) are equal or not, and it stops as soon as a difference is detected. So there is no way to compare what the difference is between two files using File::Compare, only if they are the same or not.

sounds like the bestest way to handle this is not to use a DIFF style comparison function, but merely to parse each file looking for the parameter in question.

find the parameter, extract its corresponding value, compare the value(s) to each other and/or some initial/reference value

this is the sort of thing that Perl is made for.

thanks for the advice. can u tell me where i am wrong? i have to split tha given data by "="
and " " as can b seen by the data. do i split it by array or hash?

file1:

.title 'title:VDDL_switched.meas0'
max_rush_current =   -5.4316e-02                at   = 4.9415e-09
powerup_time_u_switch_ring/u2_hs65_ls_sw3l60 =   6.3951e-09             targ = 6.9051e-09       trig = 5.1000e-10
temper           =   2.5000e+01
alter#           =   1.0000e+00

the code:

  print "First filename is $File_1 \n";
  @FieldValue1_array = "";
    $i=0;
    $j=0;


  open (FD1,"$File_1") or die("Could not open list file.");
  foreach $line1 (<FD1>) {
          $pattern = $line1;  
         #print "$pattern \n";
          ($FieldName, $FieldValue) = split(/= /,$pattern);
          #print " $FieldValue \n";
          @FieldValue1_array[$i] = $FieldValue;
            $i++;
  }
         print "First File \n";
         print "$FieldValue1_array[0] \n";
         print "$FieldValue1_array[1] \n";

the output i am getting:

#error# =Scalar value @FieldValue1_array[$i] better written as $FieldValue1_array[$i] at review.pl line .
#error#=Scalar value @FieldValue2_array[$j] better written as $FieldValue2_array[$j] at review.pl line.
no of argumnets = 2 
First filename is old.txt 
First File 
Use of uninitialized value in concatenation (.) or string at review.pl line 29, <FD1> line 5.

  -5.4316e-02                at    
  6.3951e-09             targ  
  2.5000e+01

  1.0000e+00

i am not able to extract the value for at , target, trig.
can u hepl me plz.
thanks in advance.

sounds like the bestest way to handle this is not to use a DIFF style comparison function, but merely to parse each file looking for the parameter in question.

find the parameter, extract its corresponding value, compare the value(s) to each other and/or some initial/reference value

this is the sort of thing that Perl is made for.

@FieldValue1_array[$i] = $FieldValue;

change this to $FieldValue1_array[$i] = $FieldValue; That will fix your warning

you're not getting the rest of the values in the fourth line because you're only using the first two tokens from the split:

powerup_time_u_switch_ring/u2_hs65_ls_sw3l60 = 6.3951e-09 targ = 6.9051e-09 trig = 5.1000e-10

the following line only puts the first two values of the split into variables.

($FieldName, $FieldValue) = split(/= /,$pattern);

instead try something like this:

@Fields = [split(/= /,$pattern);

and then parse through @Fields until you get to the end of the array. you'll also want to hack the meaningless garbage of the ends of your values by doing something like $CleanField = split/ /,$Fields[$j])

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.