http://www.perlmonks.org?node_id=1005019


in reply to Assistance please

As for your code, the best place to start is by adding a couple of pragmas to your script. Please you ask and if I please to tell you these? Would it be so much to ask the names? or would it be a farce to tell? of what these pragmas are and when or where they may dwell? Why for a beginner the best place to begin is the start of the script with a couple of the most delightful pragmas known to exist. Their names? Their names? oh yes! my dear friend. Now, remember to put them at the beginning and not at the end. They're both written with u's and by you and if you don't use them someone will sue! So dont hesitate and stop your yawning the first of the pragmas is use warnings! did you get that? did you write that in your script? There's no time to waste here, now type use strict! There by golly and close by gosh we got this programme under the cosh!

#! /usr/bin/perl use strict; use warnings;

Right, so I think you may have to reconsider how your hash is constructed. The plural I would use in your script would be for the hash name. This is because the hash holds all the keys. Each of the keys is a singular key. And likewise each weight is associated to a key. So to tweak your hash a little, try something like

#! /usr/bin/perl use strict; use warnings; my %Elements; my $line = 'a,H,5'; my (undef, $symbol, $weight) = split /,/, $line; $Elements{$symbol} = $weight; my $requestelement = $Elements{'H'}; my $symbolweight = $Elements{$symbol}; print $requestelement,' ',$symbolweight; ---------- 5 5

You may now find accessing the hash values clearer. Make use of the strict and warnings messages to debug, its hard at first as the messages dont make a lot of sense but after a while you know what you have done. They do really help.