Pandey Rajeev-A19514 wrote: > Hi, > > I have a list like > > @list = ( "key1: Vlan1 :0989\n" > "key2: Vlan2 :0989\n" > "key3: Vlan3 :0989\n" > "key4: Vlan4 :0989\n"); > > I wanted to make a hash with keys as key1, key2 , key3, key4. > > I want to write something like this : > ********************************************** > my @keys, @values, @key_to_value; > (@keys, @values) = map /(key\d+): (\w+).*?$/, @list; > @[EMAIL PROTECTED] = @values; > > But the problem is the map function just creates one list > i.e. @keys .. so I am not able to make the hash. > > ie .. I want to extract @keys and @values in one go and then > use the HASH SLICE to get the desired result. > > Can some one help me. The only this is I don't want to > extract @keys and @values separately.
Since map is returning a list in the form key, value, key, value, ... you can just assign directly to a hash: my %key_to_value = map /(key\d+): (\w+)/, @list; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]