Alright, I'm having a bit of difficulty assigning things to a hash. I'll explain a bit of what I'm trying to do before I paste the code in. I've got a while loop that reads in a line from the file, and splits it by the '=' sign, the first element resulting from the split is the drow word, the second is the english. I want to put all of the words into this hash with the english word as the key to each element. Here's what I've gotten so far.
#!/usr/bin/perl
print"\n";
print "\nLoading drow language list.\n";
open(DROWLANGUAGEFILE, "DrowLanguage.txt") || die "Cannot open DrowLanguage.txt";
#@drowlanguage #I can't initialize this here, bah. scope #will be off
while (<DROWLANGUAGEFILE>)
{
#chomp; #TEST CODE
#print "$_\n"; #TEST CODE
# We're going to read each line in and assign the words to an element in the hash.
@tmp= split(/=/,$_); #split the lines using the = sign.
#print"@tmp[0].....@tmp[1]\n"; #TEST CODE
@drowlanguage={@tmp[0],@tmp[1]}; #hoping this #appends to the hash, but it doesn't appear to.
#####below is test code to make sure the hash is
#right
print"Printing \@drowlanguage\n";
for($jack=0; $jack<1000; $jack++)
{
print"$drowlanguage[$jack]";
}
}
My main problems are scope; do I need to declare the hash outside of that block? Second is appending elements to the hash, this can be done right? Sorry if this is elementary, but I'm doing this off of code snippets found online, and I don't have a perl book yet.
EDIT: wow, took out all the formatting. Nasty.
#!/usr/bin/perl
print"\n";
print "\nLoading drow language list.\n";
open(DROWLANGUAGEFILE, "DrowLanguage.txt") || die "Cannot open DrowLanguage.txt";
#@drowlanguage #I can't initialize this here, bah. scope #will be off
while (<DROWLANGUAGEFILE>)
{
#chomp; #TEST CODE
#print "$_\n"; #TEST CODE
# We're going to read each line in and assign the words to an element in the hash.
@tmp= split(/=/,$_); #split the lines using the = sign.
#print"@tmp[0].....@tmp[1]\n"; #TEST CODE
@drowlanguage={@tmp[0],@tmp[1]}; #hoping this #appends to the hash, but it doesn't appear to.
#####below is test code to make sure the hash is
#right
print"Printing \@drowlanguage\n";
for($jack=0; $jack<1000; $jack++)
{
print"$drowlanguage[$jack]";
}
}
My main problems are scope; do I need to declare the hash outside of that block? Second is appending elements to the hash, this can be done right? Sorry if this is elementary, but I'm doing this off of code snippets found online, and I don't have a perl book yet.
EDIT: wow, took out all the formatting. Nasty.