I dislike using eval myself unless absolutely necessary. Why not just use linked subs:
use strict; use warnings; my (%ops, $first, $second, $op, $f); %ops = ( '+' => { 'label' => 'Sum', 'op' => sub { return $_[0] + $_[1]; } } +, '-' => { 'label' => 'Difference', 'op' => sub { return $_[0] - $_[ +1]; } }, '*' => { 'label' => 'Product', 'op' => sub { return $_[0] * $_[1]; + } }, '/' => { 'label' => 'Quotient', 'op' => sub { return $_[0] / $_[1] +; } } ); $ops{'M'} = { 'label' => 'Multiplication', 'table' => 1, 'op' => $ops{ +'*'}{'op'} }; sub getval { chomp($_ = <STDIN>); ($_) = m/($_[0])/ if $_[0]; return $_; } while (1) { print "Enter the first number: "; last if !($first = getval('\d+')); print "Enter the second number: "; last if !($second = getval('\d+')); print <<TEXT; Please enter the operation that you want to perform: + - * / M = Mulitiplication Table TEXT last if !$ops{$op = getval()}; print "\n"; if (!$ops{$op}{'table'}) { print "$ops{$op}{'label'} of $first $op $second is ", $ops{$op}{'op'}->($first, $second); } else { print ' ', join ' ', 1..$second; for $f (1..$first) { print "\n"; print join ' ', $f, map { $ops{$op}{'op'}->($f, $_) } 1..$ +second; } } print "\n\n"; }

In reply to Re: My second script by TedPride
in thread My second script by hozefa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.