Dear ikegami,
Thanks so much for your reply.
I have further question, I hope you wont' mind.
Suppose I want to:
1. Add the resulting appended hash into "%seed"
2. And then use that new appended hash in %seed
recursively again, keep appending it.
3. It stops until the length of the appended string is 3 (later can be any other length).
I tried to modify your
first example, but I'm still stuck.
The problem with my code below mainly because the %seed has doesn't get updated, only the array that grows.
What we intend is to have accumulated %seed with uniformed
length in the array element (length of the element is extended longer than the initial seed).
How should I go about it?
I am so sorry for troubling you so much. Really hope you don't mind to look at it.
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my %main = ( 'main1' => {'m1sec1'=> ['A','B','C'],},
'main2' => {'m2sec1'=> ['D','E','F']}
);
my %seed = ( 'seed' => {'seed1'=> ['X','Y','Z']},);
my @sd = keys(%seed);
OUTER: foreach my $sd ( @sd )
{
foreach my $sdsub ( sort keys %{$seed{$sd}} )
{
foreach my $valseed ( @{$seed{$sd}{$sdsub}} )
{
#--
foreach my $mn ( keys %main )
{
foreach my $msec ( sort keys %{$main{$mn}} )
{
# Create hash if it doesn't exist.
$seed{$mn."-join"} ||= {};
# Create array if it doesn't exist.
$seed{$mn."-join"}{$sdsub} ||= [];
my $store = $seed{$mn."-join"}{$sdsub};
# I want to push the new hash in the %seed key set
# (updating them)
# So that later it can be called again recursively
my $tmpstr = $mn."-join";
push @sd, $tmpstr;
foreach my $valmain( @{$main{$mn}{$msec}} )
{
push @$store, $valmain.$valseed;
last OUTER if (length($valmain.$valseed) == 4);
# length equal 4 here so that we can
# capture str with length 3 (?)
}
}
}
}
}
}
print scalar(keys %seed),"\n";
print Dumper \%seed;
---
neversaint and everlastingly indebted.......
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.