valavanp has asked for the wisdom of the Perl Monks concerning the following question:
i have used the code given by corion for the problem which i faced. I have tested with some values and the results of them are:
Only 1 value is coming correct. Other values are showing some discrepancies. I am attaching the code below:Input Output Through Code Expected Output. 4ABC 8.432 11.93544 2A2B2C 8.644 23.87 3C 4.5 4.5 ABC 4.322 2.98386
$a="ABC"; $b=length($a); print "$b\n"; for($i=0;$i<$b;$i++){ $a=~s/(\d+)(.)/$2 x $1/ge; } print "$a\n"; my %value = ( A => 2.74, B => 2.64, C => 2.5, ); my %factor = ( A => 50/100, B => 55/100, C => 60/100, ); my @letters = split //, $a; my $result = 0; my $temp=0; for my $letter (@letters) { $result=$result + $value{ $letter }* $factor{ $letter }; #print "$result\n"; }; print $result;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex and string functions help needed.
by Corion (Patriarch) on Oct 25, 2006 at 12:13 UTC | |
by valavanp (Curate) on Oct 25, 2006 at 12:32 UTC | |
Re: regex and string functions help needed.
by davorg (Chancellor) on Oct 25, 2006 at 12:36 UTC | |
Re: regex and string functions help needed.
by Samy_rio (Vicar) on Oct 25, 2006 at 13:15 UTC | |
by Hofmator (Curate) on Oct 25, 2006 at 13:36 UTC | |
Re: regex and string functions help needed.
by holli (Abbot) on Oct 25, 2006 at 16:47 UTC | |
Re: regex and string functions help needed.
by chargrill (Parson) on Oct 25, 2006 at 23:19 UTC | |
by holli (Abbot) on Oct 26, 2006 at 06:35 UTC | |
Re: regex and string functions help needed.
by doowah2004 (Monk) on Oct 25, 2006 at 13:58 UTC | |
Re: regex and string functions help needed.
by monarch (Priest) on Oct 26, 2006 at 07:43 UTC |
Back to
Seekers of Perl Wisdom