Thanx guys both of yoru techniques work, what exactly does the function map
do I cant understand.

Thanx Mark
----- Original Message -----
From: "Janek Schleicher" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, August 31, 2002 4:18 AM
Subject: Re: hash


> 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]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to