Please assist, I'm a biotech grad student trying to learn perl to make my experimental data easier to manipulate. I am writing a very simple program for conversions to start with, but am getting errors:
Any help is greatly appreciated!
my ($value, $from, $to, $prefix, %allprefixes);
%allprefixes =
(
"mega" => 6, #use these as exponents, so down below I can just
+ subtract exponents to get the answer
"kilo" => 3,
"milli" => -3,
"micro" => -6,
"nano" => -9,
"pico" => -12,
"femto" => -15,
"atto" => -18,
"zepto" => -21,
"yocto" => -24,
);
print "Enter the unit that you are starting with: ";
$from = <STDIN>;
print "Enter your target unit: ";
$to = <STDIN>;
print "Enter the numerical amount: ";
$value = <STDIN>;
chomp ($from);
chomp ($to);
chomp ($value);
if (not exists $allprefixes{$to}) {
die "My programmer has not yet supplied me with $to as a prefix\n"
+;
}
if (not exists $allprefixes{$from}) {
die "My programmer has not yet supplied me with $from as a prefix\
+n";
}
$prefix = $allprefixes{$to} -- $allprefixes{$from};
print "$value $from is ",$value*$prefix," $to. \n";
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.