You might want to use a hash of hashes (HoH) data structure to hold all of your data in one place. You can also use a while loop to read from STDIN until some end condition - here I use CTRL-D to signal eof as I'm on *nix. The Data::Dumper module is helpful when trying to visualise data and I think printf (and sprintf) will do your rounding for you.

#!/usr/bin/perl # use strict; use warnings; use feature qw{ say }; use Data::Dumper; my $prompt = q{-> }; my $dePrompt = qq{\r} . q{ } x ( length( $prompt ) + 2 ) . qq{\r}; my %RNA; print qq{Please enter name, conc. and vol. (CTRL-D to finish):\n}; print $prompt; while ( 1 ) { do { print $dePrompt; last; } if eof STDIN; chomp( my $line = <STDIN> ); my( $name, $conc, $vol ) = split m{\s+}, $line; $RNA{ $name } = { conc => $conc, vol => $vol, }; print $prompt; } print Data::Dumper->Dumpxs( [ \ %RNA ], [ qw{ *RNA } ] ); say q{-} x 50; foreach my $name ( sort keys %RNA ) { printf qq{%10s%8.2f%6d%8.2f%8.2f%8.2f\n}, $name, $RNA{ $name }->{ conc }, $RNA{ $name }->{ vol }, $RNA{ $name }->{ conc } * $RNA{ $name }->{ vol }, 30 / $RNA{ $name }->{ conc }, 50 / $RNA{ $name }->{ conc }; }

Here's a run of it.

Please enter name, conc. and vol. (CTRL-D to finish): -> Ash2 1.85 150 -> Ja2_1 1.89 150 -> Ja2_2 2.49 100 -> Set1_1 1.55 150 -> Set1_2 2.88 100 %RNA = ( 'Set1_2' => { 'vol' => '100', 'conc' => '2.88' }, 'Ja2_1' => { 'vol' => '150', 'conc' => '1.89' }, 'Ash2' => { 'vol' => '150', 'conc' => '1.85' }, 'Set1_1' => { 'vol' => '150', 'conc' => '1.55' }, 'Ja2_2' => { 'vol' => '100', 'conc' => '2.49' } ); -------------------------------------------------- Ash2 1.85 150 277.50 16.22 27.03 Ja2_1 1.89 150 283.50 15.87 26.46 Ja2_2 2.49 100 249.00 12.05 20.08 Set1_1 1.55 150 232.50 19.35 32.26 Set1_2 2.88 100 288.00 10.42 17.36

Note that my use of ^D and the $dePrompt string tidies away the last prompt. I hope this is helpful.

Cheers,

JohnGG


In reply to Re: a simple work task by johngg
in thread a simple work task by polycomb

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.