in reply to Complex Data Structures
for $type (keys %$curr_struct_pos) {
for ($a=1;$$curr_struct_pos{$type}[$a];$a++) {
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)for my $var ($begin..$end) {#blah}
Notice the 'my'? :-)my @sorted=sort {$a <=> $b} @numlist;
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:$$curr_struct_pos{$type}[$a]
Which will produce the error:use strict; use warnings; my %curr_struct_pos; my $curr_struct_pos="hello"; my $type="key"; my $index=0; $$curr_struct_pos{$type}[$index]++;
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.$path = "Global${type}Def:$$curr_struct_pos{$type}[$a].def";
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);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(); }
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Complex Data Structures
by demerphq (Chancellor) on Aug 30, 2001 at 23:52 UTC | |
by immybaby (Initiate) on Aug 31, 2001 at 14:32 UTC | |
by demerphq (Chancellor) on Aug 31, 2001 at 20:15 UTC |