Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Split string into hash

by andreas1234567 (Vicar)
on Feb 10, 2011 at 06:19 UTC ( #887344=note: print w/replies, xml ) Need Help??


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]

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://887344]
help
Chatterbox?
[LanX]: Corion can you tell WMC to check the sub version number ?
LanX has to run
[Corion]: LanX: Sure I can, but this is nothing that interests my module. It might be of concern to the user who expect the Chrome version number to have meaning ;)

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2017-12-12 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (336 votes). Check out past polls.

    Notices?