24 hours into my 1st Perl coding, and I'm jumping right into data structures. I'm testing conceptual stuff 1st.I have some questions:
1.) is the line "my %byaid" defined correctly?
2.) where I use "undef"'s, is this right?
3.) why am I not getting what I expect in the output?
Please go easy on me ... thanks!
#! /usr/perl5/5.6.1/bin/perl -w
use strict;
#use Class::Struct;
my %byaid;
my $rec = {
AID => undef,
STATUS => undef,
};
$rec->{AID} = "A";
$rec->{STATUS} = "stat-A";
$byaid{ $rec->{AID} } = $rec;
$rec->{AID} = "B";
$rec->{STATUS} = "stat-B";
$byaid{ $rec->{AID} } = $rec;
$rec->{AID} = "C";
$rec->{STATUS} = "stat-C";
$byaid{ $rec->{AID} } = $rec;
foreach my $x (keys %byaid) {
print "byaid key= ".$x."\n";
printf "AID=%s STATUS=%s\n",
$byaid{$x}{AID},
$byaid{$x}{STATUS};
}
OUTPUT:
byaid key= A
AID=C STATUS=stat-C
byaid key= B
AID=C STATUS=stat-C
byaid key= C
AID=C STATUS=stat-C
I was expecting:
byaid key= A
AID=A STATUS=stat-A
byaid key= B
AID=B STATUS=stat-B
byaid key= C
AID=C STATUS=stat-C
1.) is the line "my %byaid" defined correctly?
2.) where I use "undef"'s, is this right?
3.) why am I not getting what I expect in the output?
Please go easy on me ... thanks!
#! /usr/perl5/5.6.1/bin/perl -w
use strict;
#use Class::Struct;
my %byaid;
my $rec = {
AID => undef,
STATUS => undef,
};
$rec->{AID} = "A";
$rec->{STATUS} = "stat-A";
$byaid{ $rec->{AID} } = $rec;
$rec->{AID} = "B";
$rec->{STATUS} = "stat-B";
$byaid{ $rec->{AID} } = $rec;
$rec->{AID} = "C";
$rec->{STATUS} = "stat-C";
$byaid{ $rec->{AID} } = $rec;
foreach my $x (keys %byaid) {
print "byaid key= ".$x."\n";
printf "AID=%s STATUS=%s\n",
$byaid{$x}{AID},
$byaid{$x}{STATUS};
}
OUTPUT:
byaid key= A
AID=C STATUS=stat-C
byaid key= B
AID=C STATUS=stat-C
byaid key= C
AID=C STATUS=stat-C
I was expecting:
byaid key= A
AID=A STATUS=stat-A
byaid key= B
AID=B STATUS=stat-B
byaid key= C
AID=C STATUS=stat-C