in reply to string to expression

Maybe you just want eval? Consider:

use strict; use warnings; my @operators = qw(+ - * /); my $expression = (int rand(100)) . $operators[int rand(4)] . (int rand +(100)); my $answer = eval $expression; print "$expression = $answer";

Prints (for example):

78+63 = 141

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: string to expression
by xiaoyafeng (Deacon) on Jan 10, 2007 at 04:51 UTC
    Great!! eval looks like a best way! Thank you! I'm going to read perlfunc.

    btw.any other tutorial for eval?
    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
      Tutorial? eval EXPR runs Perl code. Any Perl code. 78+63 happens to be valid Perl. (For that reason, you'd be better with liverpole's dispatch table.)