Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Assistance please

by Don Coyote (Pilgrim)
on Nov 21, 2012 at 22:07 UTC ( #1005019=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005019]
erix .oO( note to self: running 100 syncing database instances on a single machine is hard on the hard disks )
[1nickt]: Oh, no, sins of the flesh were *especially* verboten at that monastery!

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-12-13 13:23 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (367 votes). Check out past polls.