On Oct 25, Jeff Borders said:

>I need to dump a plain text file that has the format of:
>
>key = value (ie. question <equal sign> answer)
>
>into a hash.  I'm writing a simple learning tool to help me learn some
>basic korean terminology.
>
>Would someone be kind enough to point me in the right direction.

You want to start with an empty hash:

  my %dict;

Then, when you're looping over each line of the file:

  while (<FILE>) {

you'll want to remove the ending newline,

    chomp;

and split it on the = character (with whitespace on either side):

    my ($term, $def) = split /\s*=\s*/;

Then you want to put that pair into the hash:

    $dict{$term} = $def;
  }

Using the hash, and opening the file, I leave up to you.

-- 
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to