Ok, well. Lets see.

use warnings;
use strict;

NEVER write anything with using strict and warnings, (at least until you dont have to ask questions like this :-)
Ok so now we have that out of the way, lets look at the code. Unless your description of what you want to do and what you are doing it with is completely wrong then you have some problems with your code, problems which frankly make it hard to give you a solution.
Heres your code broken down into lines.
for $type (keys %$curr_struct_pos) {

You should use the my keyword. Combined with use strict it keeps you from misspelling variables and wondering why the code has broken (amongst many other things.)
for ($a=1;$$curr_struct_pos{$type}[$a];$a++) {

This has two problems, the first being that it is not _really_ perl, but cish-perl. (A sea pearl! 8-) Its not wrong, but of a style that makes a perl programmer wonder what special things you are doing to need to use this form of 'for'. But as you arent doing anything special so it probably better to to use the more commonly used list form.
for my $var ($begin..$end) {#blah}
Overlooking that, there is a subtle error that could _really_ cause you problems if you use the sort function.(especially as you arent using my or strict or warnings)
The error I am refering to is the use of the dynamic (AKA global) variable $a.
Perl uses the global variables $a and $b to pass elements of a sort into a custom block, as below:
my @sorted=sort {$a <=> $b} @numlist;
Notice the 'my'? :-)
A question regarding this is should $a really be inited to 1? Arrays in perl start at 0 normally.
Ok the next thing is just exactly what do you mean by:
$$curr_struct_pos{$type}[$a]
I have a feeling that you think this means something that it does not. Do you think it refers to the element $a of the array stored against the key $type in some hash? Well it doesnt. The $$cur_struct_pos{... actually is a symref to whatever the scalar $cur_struct_pos happens to point at. To prove it run the following code:
use strict; use warnings; my %curr_struct_pos; my $curr_struct_pos="hello"; my $type="key"; my $index=0; $$curr_struct_pos{$type}[$index]++;
Which will produce the error:
Can't use string ("hello") as a HASH ref while "strict refs" in use at D:\Development\Perl\google\monk1.pl line 8.
So you will have to rewrite that... Maybe like $curr_struct_pos{$type}->$index;
$path = "Global${type}Def:$$curr_struct_pos{$type}[$a].def";
Ok so the same issue as before with $$curr_struct_pos. use strict; use warnings; !!!!!! And basically the rest of the code is ununderstandable because of this error.
I will provide you with what I THINK you are trying to do and maybe you can correct me.
for my $type (keys %$curr_struct_pos) { for my $index (1..@{$cur_struct_pos{$type}}-1) { $path="Global".$type. "Def:".$curr_struct_pos{$type}[$a]. ".def"; #much easier to read $curr_struct_pos{$type}[$a] = extract(); }
Now I understand you want to take the strings in the array and turn them into keys in a hash right? Well in general terms this is how you would do it (its a FAQ BTW);
my %hash; my @list=qw(These elements are going to become keys); map {$hash{$_}++} @list; #or $hash{$_}++ foreach @list; #or with refs... my $hash_ref =\%hash; my $array_ref=\@list; $hash->{$_}++ foreach @$list;

So to sum up I would say that you should go over perlreftut very carefully once again (you _have_ read it right?), and
use strict; use warnings; until you can send me a mail telling me why you dont think you should have to, and being correct in what you say.
Im sorry I dont mean to be a bitch, but the golden rule that all the newbies break is this one. Virtually all of their problems disappear when they start using it.
HTH
Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)

In reply to Re: Complex Data Structures by demerphq
in thread Complex Data Structures by immybaby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.