in reply to How to split a non even number of string elements into a hash [RESOLVED]
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to split a non even number of string elements into a hash
by choroba (Cardinal) on Feb 09, 2017 at 14:53 UTC | |
|
Re^2: How to split a non even number of string elements into a hash
by thanos1983 (Parson) on Feb 09, 2017 at 14:17 UTC |