in reply to Re: Elaborate Records, arrays and references
in thread Elaborate Records, arrays and references

@Ikegami-san,

I was looking at having ways of updating the variables on the fly, but reviewing my code passing the Elaborate Record as a parameter and localising it may work.

The one thing I am trying to do is for one subroutine to pass a Elaborate Record as a parameter to a second subroutine, this second subroutine will update the Elaborate Record and then send it back to the 1st subroutine. The two subroutines are most likely going to be in different packages so just trying to work out how to best do this.

Thanks for your reply and the help in understanding all this. I also really appreciate the final example aswell. Very helpful.
  • Comment on Re^2: Elaborate Records, arrays and references

Replies are listed 'Best First'.
Re^3: Elaborate Records, arrays and references
by ikegami (Patriarch) on Jan 06, 2011 at 17:20 UTC

    You don't need all those levels of indirect to do what you want to do either.

    use strict; use warnings; sub change_record { my ($rec) = @_; $rec->{m_username} = uc($rec->{m_username}); } { my $stg_username = "PerlMonk"; my $stg_password = "VeryGoodPassword"; my @stg_email_addresses = ( "Monk1", "Monk2", "Monk3" ); my $rec = { m_username => $stg_username, m_password => $stg_password, m_emailAddress => \@stg_email_addresses, }; print("username: $rec->{m_username}\n"); change_record($rec); print("username: $rec->{m_username}\n"); }

    The $rec inside of change_record is a different variable than the one on the outside (two "my"), but they both hold a reference to the same hash.