in reply to Re: Complex Data Structures 2
in thread Complex Data Structures 2

Yeah I know, sorry. I don't understand what you mean. I am new to Perl. The hashes which I create to put into the array should have as names the strings which were originally in the array. So for example if $file{data}1 = "hello" then I want to replace hello with the hash %hello which I then want to put equal to the hash returned by extrct().

Replies are listed 'Best First'.
Re3: Complex Data Structures 2
by Hofmator (Curate) on Aug 30, 2001 at 20:53 UTC

    Well, for being new to Perl this is a quite complicated data structure ;-). But using symbolic references is a bad idea! Why? Imagine you have already a hash called %hello in your program, this gets overwritten. And you normally don't have any influence on the values you get, so you could overwrite any hash already defined in your program. And there are more issues to that.

    The solution is simply to put everything into a new hash with the key being "hello" in your example and the value is the return value from extrct(). So you would write sth like this:

    $new_hash{$file{data}} = { extrct() }; # or if extrct returns a hash reference $new_hash{$file{data}} = extrct();

    -- Hofmator

Re: Re: Re: Complex Data Structures 2
by John M. Dlugosz (Monsignor) on Aug 30, 2001 at 20:44 UTC
    Look at the preview window before you post. Your square brackets are being eaten and turned into links! Or put <code> around things.

    So, you want to create a new global variable %hello because some input said "hello", right?

    That's what I'm questioning the wisdom of, since it's a manditory response and I was the first to answer.

    If you really want to do it, use symbolic references. to wit:

    no strict refs; $x= "hello"; $$x{bar}= "foo"; print $hello{bar}; # yup, it's there.
    You can read more about that in the perlref man page that came with Perl. I suggest you play around with it a little beore using it in the real program.

    —John