You really need to review how data in perl works--you're not going to figure it out by hacking on the keyboard.
A couple procedural hints:
- Insert print statements to print the values of variables so you can see what they contain. Sometimes they don't hold what you think they should. If you can't predict what values should be printed, then it's a sign that you don't understand something, and you need to learn it.
- It'll be difficult to learn things if you're trying to learn them while writing a big program. If your attention is divided, you'll confuse yourself. Instead write tiny scripts to teach yourself individual concepts. Make them simple and easy to understand. Once you have a handle on the ideas, it's easier to use them in a larger piece of code.
For example, here's a little program you could have written to investigate hashes. Once you understand how it works, it'll be easier to work on your project.
$ cat t.pl
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
# some data to stick into the hash
my $string1 = 'a'; # randomly generated
my $string2 = 'f'; # randomly generated
my $string3 = 'l'; # randomly generated
my $string4 = 'g'; # randomly generated
# stick them into the hash
my %hashCheckLetter;
$hashCheckLetter{$string1}=0;
$hashCheckLetter{$string4}=0;
$hashCheckLetter{$string3}=0;
$hashCheckLetter{$string2}=0;
# What does the hash actually have in it?
print Dumper(\%hashCheckLetter);
# what letters are in the hash?
for my $letter ('a' .. 'h') {
if (exists $hashCheckLetter{$letter}) {
print "Found $letter!\n";
}
else {
print "Letter $letter not available\n";
}
}
When run, it produces this:
$ perl t.pl
$VAR1 = {
'l' => 0,
'a' => 0,
'g' => 0,
'f' => 0
};
Found a!
Letter b not available
Letter c not available
Letter d not available
Letter e not available
Found f!
Found g!
Letter h not available
...roboticus
When your only tool is a hammer, all problems look like your thumb. |