Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need help to debug my perl

tonyntonyn Posts: 7Member
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

  • old_Joeold_Joe Posts: 8Member
    : 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

  • tonyntonyn Posts: 7Member
    : : 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.