http://www.perlmonks.org?node_id=887344


in reply to Split string into hash

Your code contains syntax errors, and had you used warnings you would have gotten some hints on what is wrong. I would do something like this:
$ perl use strict; use warnings; use Data::Dumper; my $string="1:one;2:two;3:three"; my %hash; my @list1 = split /;/, $string; foreach my $item(@list1) { my ($i,$j)= split(/:/, $item); $hash{$i} = $j; } print Dumper \%hash; __END__ $VAR1 = { '1' => 'one', '3' => 'three', '2' => 'two' }; $
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]