Hello thanos1983,
How about this?
use strict; use warnings; use Data::Dumper; my $string = "one 1 two 2 three 3 odd_element"; my @elements = split / /, $string; push @elements, undef if @elements % 2; my %hash = @elements; print Dumper \%hash;
Output:
22:41 >perl 1750_SoPW.pl $VAR1 = { 'three' => '3', 'odd_element' => undef, 'two' => '2', 'one' => '1' }; 22:42 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: How to split a non even number of string elements into a hash
by Athanasius
in thread How to split a non even number of string elements into a hash [RESOLVED]
by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |