Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need help to debug my perl Posted by tonyn on 27 Dec 2007 at 9:57 PM
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 = <STDIN>);
my $a = "test";

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

while (<IN>) {
if ($device eq 'pfet') {
if (/\bpfet/) {
@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\n", $total_area_pfet_reduce;

Attachment: test (216 Bytes | downloaded 118 times)
Report
Re: Need help to debug my perl Posted by old_Joe on 28 Dec 2007 at 11:41 AM
: 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 = <STDIN>);
: my $a = "test";
:
: open(IN,$a) || die "can not open $a for reading: $!";
:
: while (<IN>) {
: if ($device eq 'pfet') {
: if (/\bpfet/) {
: @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\n", $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

Report
Re: Need help to debug my perl Posted by tonyn on 28 Dec 2007 at 11:52 AM
: : 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 = <STDIN>);
: : my $a = "test";
: :
: : open(IN,$a) || die "can not open $a for reading: $!";
: :
: : while (<IN>) {
: : if ($device eq 'pfet') {
: : if (/\bpfet/) {
: : @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\n", $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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.