I need help creating a hash. I am Stumped!

I need to create a hash by parsing the following information.  I would like my hash to look like this.

%Hashname (
            template:Actioncode => i
            SBID       => 100200401
            BusName    => Mikes System Test1
            City       => Douglas
            State      => MA
            Zip        => 01516
            Phone      => 5084742781
            CategoryID => 14438

This is the information that I would be parsing in the file.  The idea is to recreate the hash for each line below the template line.
I would greatly appreciate this.  One thing to note is that the script would have to be dynamic becuase the template line wont always look like that.  It could have extra fields.  Thank you!

i|100200401|Mikes System Test1|Douglas|MA|01516|5084742781|14438
i|100200402|Mikes System Test2|Douglas|MA|01516|5084742782|14438
i|100200403|Mikes System Test3|Douglas|MA|01516|5084742783|14438
i|100200404|Mikes System Test4|Douglas|MA|01516|5084742784|14438
i|100200405|Mikes System Test5|Douglas|MA|01516|5084742785|14438

Here's all i got now.

# open up the text file to parse.
open (IUD, "SomeTextfile.txt") or die "Can't open textfile: $!";
while (<IUD>)
   # create my hash

close IUD;

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

use strict;

open IUD, "SomeTextfile.txt" or die "Can not open textfile: $!\n";

chomp ($_) = <IUD>;
my @fields = split(/\|/);
my %hash;

while (<IUD>) {
  my $i=0;
  foreach split(/\|/) {
    $hash{$fields[$i]} = $_;

close IUD;

However, I'm sure someone will come up with a 1 line map solution.
use Data::Dumper;
use strict;

open (IUD, "t.txt") or die "Can't open textfile: $!";

# split fields line
my $line = <IUD>; chomp ($line);
my @f = split (/\|/, $line);
my @data = ();
my %data = ();

while ($line = <IUD>)
  # split value line
  chomp ($line);
  my @v = split (/\|/, $line);

  # create my hash
  my %h = map { $f[$_], $v[$_] } (0..$#v);

  # build array of hashes
  push @data, \%h;

  # or hash of hashes with SBID as field
  $data{$f[1]} = \%f;


print Dumper (\@data);
close IUD;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maddhacker24Author Commented:
Thank you very much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.