Need help to debug my perl

Hi,

I want to write a perl code to calculate total area of device pfet but the result is wrong.

The total_area_pfet_reduce = (1.5*0.325)+ (1*0.325) =0.8125

but my perl code give the the wrong result 1.3 because

(1.5*0.325) + (1*0.325) + (1.5*0.325) = 1.3

I do not why it add 3 times instead of 2 times


What I like to do is open the file test.cdl and find "pfet" then search for l=0.325 then add all w*l. If l is not equal 0.325 then ignore that area.

Many thanks,
Tony

#!/usr/bin/perl
###################################################################################
#

print " Enter device name:";
chomp(my $device = );
my $a = "test";

open(IN,$a) || die "can not open $a for reading: $!";

while () {
if ($device eq 'pfet') {
if (/pfet/) {
@str_array = split(/=/,$_);
if ($str_array[2] = 0.325) {
$area_reduce_pfet = $str_array[1]*$str_array[2];
$total_area_pfet_reduce += $area_reduce_pfet;
}
}

}
}

printf "total_area_pfet_reduce %.2f%s
", $total_area_pfet_reduce;

Comments

  • : Hi,
    :
    : I want to write a perl code to calculate total area of device pfet
    : but the result is wrong.
    :
    : The total_area_pfet_reduce = (1.5*0.325)+ (1*0.325) =0.8125
    :
    : but my perl code give the the wrong result 1.3 because
    :
    : (1.5*0.325) + (1*0.325) + (1.5*0.325) = 1.3
    :
    : I do not why it add 3 times instead of 2 times
    :
    :
    : What I like to do is open the file test.cdl and find "pfet" then
    : search for l=0.325 then add all w*l. If l is not equal 0.325 then
    : ignore that area.
    :
    : Many thanks,
    : Tony
    :
    : #!/usr/bin/perl
    : #####################################################################
    : ##############
    : #
    :
    : print " Enter device name:";
    : chomp(my $device = );
    : my $a = "test";
    :
    : open(IN,$a) || die "can not open $a for reading: $!";
    :
    : while () {
    : if ($device eq 'pfet') {
    : if (/pfet/) {
    : @str_array = split(/=/,$_);
    : if ($str_array[2] = 0.325) {
    : $area_reduce_pfet = $str_array[1]*$str_array[2];
    : $total_area_pfet_reduce += $area_reduce_pfet;
    : }
    : }
    :
    : }
    : }
    :
    : printf "total_area_pfet_reduce %.2f%s
    ", $total_area_pfet_reduce;
    :
    :

    You might want to check your condition in your third "if" clause.
    If you are trying to test to see if $str_array[2] = 0.325, then
    I suggest changing your condition to have am equal operator "=="
    rather than the current assignment operator "=" your using in it.

    All the Best!
    Old Joe

  • : : Hi,
    : :
    : : I want to write a perl code to calculate total area of device pfet
    : : but the result is wrong.
    : :
    : : The total_area_pfet_reduce = (1.5*0.325)+ (1*0.325) =0.8125
    : :
    : : but my perl code give the the wrong result 1.3 because
    : :
    : : (1.5*0.325) + (1*0.325) + (1.5*0.325) = 1.3
    : :
    : : I do not why it add 3 times instead of 2 times
    : :
    : :
    : : What I like to do is open the file test.cdl and find "pfet" then
    : : search for l=0.325 then add all w*l. If l is not equal 0.325 then
    : : ignore that area.
    : :
    : : Many thanks,
    : : Tony
    : :
    : : #!/usr/bin/perl
    : : #####################################################################
    : : ##############
    : : #
    : :
    : : print " Enter device name:";
    : : chomp(my $device = );
    : : my $a = "test";
    : :
    : : open(IN,$a) || die "can not open $a for reading: $!";
    : :
    : : while () {
    : : if ($device eq 'pfet') {
    : : if (/pfet/) {
    : : @str_array = split(/=/,$_);
    : : if ($str_array[2] = 0.325) {
    : : $area_reduce_pfet = $str_array[1]*$str_array[2];
    : : $total_area_pfet_reduce += $area_reduce_pfet;
    : : }
    : : }
    : :
    : : }
    : : }
    : :
    : : printf "total_area_pfet_reduce %.2f%s
    ", $total_area_pfet_reduce;
    : :
    : :
    :
    : You might want to check your condition in your third "if" clause.
    : If you are trying to test to see if $str_array[2] = 0.325, then
    : I suggest changing your condition to have am equal operator "=="
    : rather than the current assignment operator "=" your using in it.
    :
    : All the Best!
    : Old Joe
    :
    :
    Hi Old Joe,

    Thanks for helping me. It is working.

    This is the first time I post my question. This forum is very helpul.

    Many thanks,
    Tony
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories