I have a function similar to the following:
sub sub_pick_group_seg { my ($str) = @_;
my $working=$str;
my @groups;
while ( $working =~ s/<\@=([\w\d\_\ ]+)>(.*?)<\/\@=\1>/<\@=\1>/gs )
{
my $name=$1;
my $newvalue=$2;
if ($name ne "")
{
my $gcount=@groups;
my @subgroup;
my $newvalue;
($newvalue, @subgroup)=sub_pick_group_seg ($newvalue);
$groups[$gcount]{name}=$name;
$groups[$gcount]{value}=$newvalue;
my $subcount=@subgroup;
if ( $subcount > 0 )
{
$groups[$gcount]{sub}=@subgroup;
}
}
}
return ($working, @groups);
}
Where all works, except at line:
$groups[$gcount]{sub}=@subgroup;
There, the function should have called itself previously, and if it got values, tack them onto this hash/array. I haven't really figured out references, so I'm fairly sure this is where I'm going wrong. How would I make it so that
$groups[$gcount]{sub} gets values, par example so I can pull:
$groups[0]{sub}[0]{name}or even
$groups[0]{sub}[0]{sub}[2]{name}
it should keep going in this way.
update: Worked with
$groups[$gcount]{sub}=@subgroup;
However, now when pulling values: I get an error with this code:
my $arr= @group[$indx];
print "---*--- " . join(",", keys(%$arr) ) . "<br>\n";
print "--+ " . $$arr{name} . "<br>\n";
Which is odd since the output is:
---*--- value,name<br>
Bad index while coercing array into hash at ./mod/subst.cgi line 65.
If there is a key called "name" (as indicated by the first return line), should $$arr{name} be a valid call?
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.