in reply to Computed "my" declarations?

Maybe it's just me, but I can't understand what the hell you're trying to accomplish. Why do you declare a set of lexical variables, then declare another list containing the names of the lexicals? Why does your example involve package variables with the same names as lexicals? What are you trying to accomplish?

Replies are listed 'Best First'.
Re^2: Computed "my" declarations?
by Anonymous Monk on Oct 26, 2005 at 23:11 UTC
    I don't want to use a hash key like 'name' because other classes in the hierarchy may already be using that. So I will use __PACKAGE__ . '::name' instead to avoid the conflict. But I would rather not have to write that every time I reference the value of the field. So I am trying to declare $name with value __PACKAGE__ . '::name', $timestamp with value __PACKAGE__ . '::timestamp', etc. so that I can refer to my package's fields with the simpler $self->{$name}.

    The question was how to do that without having to repeat the list of field names with my ($name, $timestamp, ...) = map {...} ('name', 'timestamp', ...);

    Thanks,
    A.C., oops, pm not /. so I guess that's A.M.

      Better than a timestamp, store another hash in a key named after your package. In your Foo->new method, store a hash ref.

      sub foo { my $self = shift; my $data = $self->{+__PACKAGE__}; $data->{...} }
           I don't want to use a hash key like 'name' because other
           classes in the hierarchy may already be using that.
      
      You should strongly consider converting over to using inside-out objects which avoids this hassle altogether. Start by looking at Class::Std.

      Remember: There's always one more bug.