> Hi,
>
> I have a variable for which I ultimately want to substitute w/ some
> math. Is there a way to get the result "6"?
>
> my $number=123;
> $number =~s/123/1+2+3/s; #This method results in "1+2+3", not the "6"
> I am looking for
> print "$number";


Run this program and see if you can see what is going on.


Owen

===========================================


#!/usr/bin/perl -w

use strict;

my $number = 123;
my $total  = 0;
my @bits   = split //, $number;

print "$bits[0] $bits[1] $bits[2]\n";

my $added = $bits[0] + $bits[1] + $bits[2];

print "$added\n";

foreach my $nr (@bits) {
    $total = $total + $nr;
}

print "$total\n";

===========================================


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to