T
Todd Pytel
Hello again,
For various reasons that I won't go into here, I'm ending up with a string
like "1 + 2 + 3" that I'd like to evaluate as an arithmetic expression.
How can I "cast" that string to a number? For example, if I can get
$newnumber in the following snippet to equal 13 instead of 8, then I'm set:
#!/usr/bin/perl
my $string = "1 + 2 + 3";
print "String is $string.\n";
my $number = 7;
print "Number is $number.\n";
my $newnumber = $number + $string;
print "Newnumber is $newnumber.\n";
At the moment, I'm solving the problem using `expr`, but it seems very
nasty relying on the system for this.
Thanks,
Todd Pytel
For various reasons that I won't go into here, I'm ending up with a string
like "1 + 2 + 3" that I'd like to evaluate as an arithmetic expression.
How can I "cast" that string to a number? For example, if I can get
$newnumber in the following snippet to equal 13 instead of 8, then I'm set:
#!/usr/bin/perl
my $string = "1 + 2 + 3";
print "String is $string.\n";
my $number = 7;
print "Number is $number.\n";
my $newnumber = $number + $string;
print "Newnumber is $newnumber.\n";
At the moment, I'm solving the problem using `expr`, but it seems very
nasty relying on the system for this.
Thanks,
Todd Pytel