#!/usr/bin/perl -w
...
use warnings;
...
BEGIN { $^W = 1; }
sub BEGIN {
if ($^W == 1) {say "Let's get started..."}
else {die $@}
}
Why do you want to turn on warnings 3 times and then die if they're not turned on? use warnings; is sufficient for anything but an ancient version of perl, in which case you might need the -w switch.
my $resistance = <STDIN>;
if ($current =~ /mA/) {
$current =~ s/mA//;
$current =~ s/(^\s+| )//;
$current /= 1000;
}
That's kind of a mess. First you match on mA and then remove mA, not to mention that it will fail on bad input. Consider an answer like 0 or "more amps than you'll ever know!" It's much better to extract the expected input and complain if you can't find it. The following is a quick, untested example...
my $input = <STDIN>;
my ($current) = $input =~ /^\s*[\d.]+\s+/ or do {
error_stuff();
... # next, redo, or return, as appropriate
};
$input =~ /\s+mA\s*$/ and $current /= 1000;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|