in reply to Re^3: How can I access package variables in a dynamic way
in thread How can I access package variables in a dynamic way

I do like this, but in my actual use case (which I didn't mention, sorry) I don't know how many $nums there will be.
  • Comment on Re^4: How can I access package variables in a dynamic way

Replies are listed 'Best First'.
Re^5: How can I access package variables in a dynamic way
by Corion (Patriarch) on Feb 12, 2019 at 15:47 UTC

    In that situation, you will have to inspect the hash %Person:: and hope that all the variable slots have actually been assigned.

      Agreed... although this is really moving into "hack" territory, my code from here could be extended to:

      my $amax; for ($amax=1; exists $Person::{"address_$amax"}; $amax++) {} $Person::addresses = sub{\@_}->( map { no strict 'refs'; ${"Person::address_$_"} } 1..$amax-1 );