in reply to Re: add element to hash
in thread add element to hash

Hey, thanks for your quick Respons. You understand what I mean, but it did not work properly. I will specify my question. I'm working with the GDS2Stream module of perl. So I try to create from an inputfile a gds-file recursivly. There is the beginning of one structure and the end of a structure. It Looks like this:
Begin of structure-> #something to draw #anything else to draw #something to draw End of Structure Begin of structure-> #something to draw end of structure
The begin of structure is a specific Name. And means the key of my hash. Every key contains rrays which are a list of every element I Need to draw within in this structure. The elements of the Array differs from key to key. So this means the first key is able to have about 10 elements and the second key is able to have about 50 elements;
%hash{@structure_name1} => {[@draw1, @draw2,]}; %hash{@structure_name2} => {[@draw1, @draw2, @draw3]};
And my idea was to find the last element of this Array in the structure and add the end of structure (equal with command printEndstr of the modul)like this:
%hash{@structure_name1} => {[@draw1, @draw2,"$gds2File->printEndstr]}; %hash{@structure_name2} => {[@draw1, @draw2, @draw3, $gds2File->printE +ndstr]};
The Problem is, that in gdsFile there are more Ends of structure and beginnings of structure. I Thing the Problem is the recursion or something like that

Replies are listed 'Best First'.
Re^3: add element to hash
by roboticus (Chancellor) on Sep 01, 2014 at 11:28 UTC

    You're incorrectly inserting braces, parenthesis and brackets at several points in your two posts. This really isn't helping you out. You don't seem to have a good handle on them, and they're very important to be able to understand how to access and use data structures in perl. I suggest you read perldsc, perlreftut, perllol and company.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re^3: add element to hash
by NetWallah (Canon) on Sep 01, 2014 at 14:31 UTC
    Please take a close look at the code Athanasius (++) posted - I believe that is very close to what you are trying to do - except his code has the correct syntax.

    The only thing I can guess differently about how your structure might look is to replace the initial hash assignment with:

    my %hash = ( key1 => [ @array1, @array2, ], # Assign array elements, not refere +nces. );

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams