I condensed it a bit. This is closer to how I would do it:
#!/usr/bin/perl -sl BEGIN { $^W = 1; } sub BEGIN { if ($^W == 1) { print "Let's get started...\n"; } else { die $@; } } use strict; use warnings; use English qw(-no_match_vars); local $OUTPUT_AUTOFLUSH = 1; local $OUTPUT_RECORD_SEPARATOR = *\ ; print "I will calculate whatever \n", "you specify according to\n", "Ohm's law. What shall I\n", "calculate? Type either\n ", "voltage, current, or \n", "resistance.\n"; my $i = 0; while ($i == 0) { my $calculation = <STDIN>; if ($calculation =~ /voltage/) { print "Type the current of the circuit.\n", "Add mA at the end of your answer\n", "if your answer is in milliAmps.\n"; chomp(my $current = <STDIN>); print "Now type the resistance of the circuit.\n"; chomp(my $resistance = <STDIN>); if ($current =~ /mA/) { $current =~ s/mA//; $current =~ s/^\s+//; $current =~ s/ //; $current /= 1000; } else { (); } my $voltage = $current * $resistance; print "Ohm's law is V = IR, so the voltage of\n"; print "the circuit is $voltage volts.\n"; ++$i; } elsif ($calculation =~ /current/) { print "Type the resistance of the circuit.\n"; chomp(my $resistance = <STDIN>); print "Now type the voltage of the circuit.\n"; my $voltage = <STDIN>; my $current = $voltage / $resistance; my $otherCurrent = $current / 1000; print "Ohm's law is V = IR, so the current of\n", "the circuit is $current amps\n", "or $otherCurrent milliAmps.\n"; ++$i; } elsif ($calculation =~ /resistance/) { print "Type the current of the circuit.\n", "Add mA at the end of your answer\n", "if your answer is in milliAmps.\n"; chomp(my $current = <STDIN>); print "Now type the voltage of the circuit\n."; my $voltage = <STDIN>; if ($current =~ /mA/) { $current =~ s/mA//; $current =~ s/^\s+//; $current =~ s/ //; $current /= 1000; } else { (); } my $resistance = $voltage / $current; print "Ohm's law is V = IR, so the resistance of\n", "the circuit is $resistance ohms.\n"; ++$i; } else { print "That is not a valid answer.\n" "Retype your answer.\n"; } }
Update: made a few additions.

In reply to Re: What makes good Perl code? by Khen1950fx
in thread What makes good Perl code? by slinky773

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.