D
Diandian Zhang
Hi, everyone,
I think the question is strange. But I really want get the value of
mathematical formal given in form of a string. For example from the
string "256 - 64", I want get the value (256 - 64). What I did was:
my $str = "256 - 64";
my @arr = split (/ /, $str);
my $value;
if (@arr[1] eq "-") {
$value = @arr[0] - @arr[2];
}
elsif (@arr[1] eq "+") {
$value = @arr[0] + @arr[2];
}
elsif (...) {
...;
}
Are there any better ways to solve the problem? Thanks!
I think the question is strange. But I really want get the value of
mathematical formal given in form of a string. For example from the
string "256 - 64", I want get the value (256 - 64). What I did was:
my $str = "256 - 64";
my @arr = split (/ /, $str);
my $value;
if (@arr[1] eq "-") {
$value = @arr[0] - @arr[2];
}
elsif (@arr[1] eq "+") {
$value = @arr[0] + @arr[2];
}
elsif (...) {
...;
}
Are there any better ways to solve the problem? Thanks!