in reply to Re^2: better way to convert a string into an array and an hash
in thread better way to convert a string into an array and an hash
Indeed.
There are a number of ways to preserve the order. Here's a slightly whimsical one:
or another:my $string = "1:1,2:1,3:2,500:2,505:1"; my %hash = split /[:,]/, $string; my @array = split /:.+?,?/, $string; # :-)
But these probably drive the original split idea far far into the ground :-)my $string = "1:1,2:1,3:2,500:2,505:1"; my %hash = my @array = split /[:,]/, $string; @array = @array[grep $_%2==0, 0..$#array];
|
|---|