in reply to possible to assign symbolic references?

if ($open_tag eq 'div'

You don't actually use references, symbolic or otherwise. You're asking to create aliases.

It's actually possible to do what you want without even using Data::Alias.

push @{ $this->{local_vars} }, sub { \@_ }->(my ( $open_tag, $tagprint, $cur_class, $cur_id, $defines_class, $defines_id, )); ... if ($open_tag eq 'div' and $cur_class eq 'pager') {...

Of course, it might wiser to actually use references.

my @local_vars; push @{ $this->{local_vars} }, \@local_vars; my ( $open_tag, $tagprint, $cur_class, $cur_id, $defines_class, $defines_id, ) = \@local_vars[0..5]; ... if ($$open_tag eq 'div' and $$cur_class eq 'pager') {...

Replies are listed 'Best First'.
Re^2: possible to assign symbolic references?
by perl-diddler (Chaplain) on Sep 21, 2010 at 23:08 UTC
    Why would using references be preferable? Is use of Data::aliases expensive (or more so) than using a dereference on each access?

      Aliases would be less expensive once created. However, using aliases introduces more magic (especially if Data::Alias is involved) and creates more action at a distance (making the code less clear and harder to debug).

      Actually, even simpler would be to use neither. The problem only exists because the addition of the scalars to the data structure is done at the top of the code.

      my ($var1, $var2, ...); ... push @array, [ $var1, $var2, ... ];

      The downside is that you might have to guard against exceptions and returns.

        I think Data::aliases is exactly what I was looking for. I didn't know it existed (guess I should have thought to look under aliases!)...

        This comment in the Data::Aliases description fits my situation perfectly:

        You can use this to improve efficiency and readability, when compared to using references.
        Thanks!

      Real references are solid, dependable things.

      Symbolic references are a leap of faith that will kill you eventually.