in reply to split question
The output is:use Data::Dumper; # to let us print out the results at the end my $var = "xxx:12345 yyy:54321 zzz:13245"; my %hash = $var =~ /(\S+):(\d+)/g; # a pattern match in array context returns a list of the matches # and hash is a list in which odd-numbered items are keys and even- # numbered items are values print Dumper(\%hash);
The disadvantage of this is that it does depend on regular input and won't tell you if there is a breakdown in the input, but just spit out rubbish. Better to get a module for general use.$VAR1 = { 'yyy' => '54321', 'xxx' => '12345', 'zzz' => '13245' };
|
---|