in reply to Re: Combinations of lists, etc
in thread Combinations of lists to a hash
And the output:#!/usr/bin/perl while (<DATA>) { #($pre, $ranges) = split /=/, $_, 2; ($pre, $ranges, $value) = $_ =~ /^(.+?)=([^ ]+) (.+)$/; $del = "="; @keys = $pre; for $mult (split /:/, $ranges) { @keys = map { $a=$_; map { "$a$del$_" } split /,/, $mu +lt } @keys; $del = ':'; } #@hash{@keys} = ('value2') x @keys; @hash{@keys} = ($value) x @keys; } use Data::Dump 'dd'; dd \%hash; __DATA__ Prefix1=A,B:c,d value1 Prefix2=A:b,c:1,2 value2 Prefix3=A:*:1,2 value3
If you have any suggested changes to my changes, I'm all ears.{ "Prefix1=A:c" => "value1", "Prefix1=A:d" => "value1", "Prefix1=B:c" => "value1", "Prefix1=B:d" => "value1", "Prefix2=A:b:1" => "value2", "Prefix2=A:b:2" => "value2", "Prefix2=A:c:1" => "value2", "Prefix2=A:c:2" => "value2", "Prefix3=A:*:1" => "value3", "Prefix3=A:*:2" => "value3", }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Combinations of lists, etc
by LanX (Saint) on Oct 05, 2019 at 01:06 UTC | |
by tel2 (Pilgrim) on Oct 05, 2019 at 01:58 UTC | |
by LanX (Saint) on Oct 05, 2019 at 13:57 UTC | |
by tel2 (Pilgrim) on Oct 07, 2019 at 06:59 UTC | |
by AnomalousMonk (Archbishop) on Oct 07, 2019 at 07:40 UTC | |
| |
by LanX (Saint) on Oct 07, 2019 at 07:26 UTC | |
|