in reply to Elaborate Records, arrays and references
The first error would have been caught by use strict;. Don't hide errors; use use strict; use warnings;.
$$reference->[m_emailAddress]
should be
$$reference->{m_emailAddress}
Secondly, you treat $$reference->{m_emailAddress} as a reference to an (anonymous) array of addresses. It is really a reference to a reference to an (anonymous) array that contains one reference to an (anonymous) array of addresses.
$$reference->{m_emailAddress}->[0]
should be
${ $$reference->{m_emailAddress} }->[0]->[0]
What's with references to scalars and the crazy stacking of references?
use strict; use warnings; sub print_record { my ($rec) = @_; print("username: $rec->{m_username}\n"); print("password: $rec->{m_password}\n"); print("email: @{ $rec->{m_email_addresses} }\n"); } my $stg_username = "PerlMonk"; my $stg_password = "VeryGoodPassword"; my @stg_email_addresses = ( "Monk1", "Monk2", "Monk3" ); my $ellab_rec = { m_username => $stg_username, m_password => $stg_password, m_emailAddress => \@stg_email_addresses, }; print_record($ellb_rec);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Elaborate Records, arrays and references
by KyussRyn (Acolyte) on Jan 06, 2011 at 04:44 UTC | |
by ikegami (Patriarch) on Jan 06, 2011 at 17:20 UTC |