in reply to Re: Error using Data::Alias (how to allocate array w/o filling it in?) and help avoiding 'constant' len?
in thread Error using Data::Alias (how to allocate array w/o filling it in?) and help avoiding 'constant' len?

Actually turning it around helped me avoid the alias altogether -- save the vars on the 'stack', and not have to worry about early exists while having the saved values still being updated on the stack... Got rid of 'local_vars' array entirely, and now I just push them all on at creation time onto the stack:
push @{this-{local_vars}], [my ($open_tag, $tag_print, $cur_class, $cur_id, $defines_class, $defines_id, $tag_output )];
Came close to forgetting the square brackets until I was about to explain what I did here! Then I saw,, oops, I'm pushing 7 successive values onto @local_vars, instead of pushing 1 array containing them! Doh! But try to explain what I did, and caught that right off!

Good illustration of why sometimes I snag some non-CS literate friend into helping look for some programing problem while I explain it to them in a way they can understand it -- meaning I really have to be very explicit as to what is going on -- maybe even with diagrams. Embarrassingly amazing how many times I catch my own bugs that way.

I try to explain to them, that they really are performing a valuable function -- even if they don't understand everything, because when you explain your code so a non-CS person can understand it, you have to explain every assumption, and the effect of every operator...

  • Comment on Re^2: Error using Data::Alias (how to allocate array w/o filling it in?) and help avoiding 'constant' len?
  • Download Code

Replies are listed 'Best First'.
Re^3: Error using Data::Alias (how to allocate array w/o filling it in?) and help avoiding 'constant' len?
by ikegami (Patriarch) on Sep 23, 2010 at 18:24 UTC

    huh?

    push @{$this->{local_vars}}, [my ($open_tag, $tag_print, $cur_class, $cur_id, $defines_class, $defines_id, $tag_output )]; $open_tag = 123; use Data::Dumper; print(Dumper($this));
    $VAR1 = { 'local_vars' => [ [ undef, undef, undef, undef, undef, undef, undef ] ] };

    Mind you, putting the assignment to local_vars at the bottom will avoid aliases. That's the solution I suggested in your earlier thread.

    my ($open_tag, $tag_print, $cur_class, $cur_id, $defines_class, $defines_id, $tag_output ); $open_tag = 123; push @{$this->{local_vars}}, [$open_tag, $tag_print, $cur_class, $cur_id, $defines_class, $defines_id, $tag_output];
    $VAR1 = { 'local_vars' => [ [ 123, undef, undef, undef, undef, undef, undef ] ] };