in reply to eval question
#!/usr/bin/perl -w use strict; use warnings; my $p_operations = { '+' => sub { $_[0] + $_[1] }, '-' => sub { $_[0] - $_[1] }, '*' => sub { $_[0] * $_[1] }, '/' => sub { $_[0] / $_[1] }, }; # Get operation $op, and values $x and $x in whatever fashion # ... # For testing my $x = 12; my $y = 7; my $op = "*"; my $result = $p_operations->{$op}->($x, $y); print "The result of $x $op $y is: $result\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: eval question
by jdrago_999 (Hermit) on Apr 16, 2007 at 14:58 UTC | |
by ikegami (Patriarch) on Apr 16, 2007 at 15:19 UTC | |
by liverpole (Monsignor) on Apr 16, 2007 at 15:11 UTC | |
|
Re^2: eval question
by Anonymous Monk on Apr 17, 2007 at 04:48 UTC | |
by ikegami (Patriarch) on Apr 17, 2007 at 05:24 UTC |