Perl Read File, Break up the values, store them off?

Jason

New member
I need to read in a file, rip apart each line, and store them into a hashmap.

I know how to read in the file, and store the values into a hash map, but I can't figure out how to break apart the string. I know of Pattern Matching with regular expressions, but I don't know how to store it off.

Here's the idea:

Data:
Coa.jar
Extasys.jar
FastInfoset.jar jaxb-impl.jar, jaxws-rt.jar
Geo.jar Coa.jar
Jama-1.0.1.jar bcToolbox.jar
Jmathtools.jar Coa.jar, bcToolbox.jar
KBClient.jar ontology.jar
KBODDS.jar KBClient.jar, ontology.jar
Lpsolve.jar Coa.jar

The space in between the first jar name and the second is a tab.
What I want to get out of it:

key -> value
where the key is the first word in the list, and the value is the rest of the strings. From there, I have an idea what I want to do with the values, but it's first getting them out.

Here's the code I have so far:

#!/usr/bin/perl -w
use strict;

my $origfile = shift;

my %hash = ();

open (IN, "<$origfile") or die "Couldn't open input file: $!";

while (my $sLine = <IN>) {
$hash{$sLine} = "value from parse";
print("key hash{$sLine} --> $hash{$sLine}\n");
}

close IN;
 
Back
Top