Mark Goland wrote at Sat, 31 Aug 2002 13:26:02 +0200: > hi guys, I am trying to extractract a string and use it as a hashkey. Here > is an example of what I mean; > > input: > ad0: hard drive > fd0: floppy drive > xl:network card
Sometimes a simple colon ':', sometimes a colon + blank ': ' ?! > > How I would liek the hash to be assigned; > > hash{ad0}="hard drive" > hash{fd0}="floppy drive" > hash{xl}="network card" > What have you tried so far ? Let's assume the input can be found in $input. Then something like foreach my $line (split /\n/, $input) { my ($key, $value) = split /:\s*/, $line; $hash{$key} = $value; } should work. Of course, that also can be written shorter as my %hash = map {split /:\s*/} split /\n/, $input; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]