in reply to Missing something with regards to references

Err, if you have a sub you call like this:

put_element($DATA{3}, 'h', 'i', 'worked');

Why not just do:

$DATA{3}{h}{i}='worked';

Why write a sub to do it? Or am I missing something?

cLive ;-)

update: I am missing something, but I don't get exactly what on rereading your question ;-)

Replies are listed 'Best First'.
Re^2: Missing something with regards to references
by scottb (Scribe) on Nov 01, 2004 at 22:39 UTC
    What you're missing is that this is an example, this is not the actual application or the proper use of the function. It's been simplified in order to be able to directly address the issue I am having without the confusion of the full complexity of the program.

    The whole point of a data structure is to be dynamic... and if it's dynamic then I wont know whether I'm assigning to $DATA{3}{h}{i}, or $DATA{3}{h}{i}{j}, or $DATA{3}{h}{i}{j}{k}. So I need a function that adapts to the number of dimensions of the hash dynamically.

      Right, but my point is, what are you trying to achieve by calling this:
      put_element($DATA{3}, 'h', 'i', 'j', 'k', 'value');

      rather than this:

      $DATA{3}{h}{i}{j}{k} = 'value'

      I don't see how the sub optimizes anything, or provides anything that a direct call does.

      Unless you're calling it like this:

      my @arr = qw(h i j k); put_element($DATA{3}, @arr, 'value');

      Is that how you're using it?

      cLive ;-)