stu96art has asked for the wisdom of the Perl Monks concerning the following question:
I have this hash:
The values are assigned from a *.csv file, but I want to show what the structure looks like.
$flag_assignments{$key}{"starrez"} = $info[0]; $flag_assignments{$key}{"abbreviation"} = $info[1]; $flag_assignments{$key}{"greek"} = $info[2]; $flag_assignments{$key}{"Fall"} = $info[3]; $flag_assignments{$key}{"Spring"} = $info[4]; $flag_assignments{$key}{"Summer"} = $info[5]; $flag_assignments{$key}{"RA-Fall"} = $info[6]; $flag_assignments{$key}{"RA-Spring"} = $info[7]; $flag_assignments{$key}{"RA-Summer"} = $info[8]; $flag_assignments{$key}{"NR-Fall"} = $info[9]; $flag_assignments{$key}{"NR-Spring"} = $info[10];
The %starrez hash is a list of patrons in which we are deciding which of the %flag_assignments values we are assigning to them.
The hash stays as I want it (only with the keys that are assigned from the *.csv file until I get to this point in the code. I have attached the code that is adding keys to my hash below:
for my $key (sort keys %starrez) { if (exists $starrez{$key}{"dorm"}) { } else { $starrez{$key}{"dorm"} = "None"; } if (exists $starrez{$key}{"greek"}) { } else { $starrez{$key}{"greek"} = "None"; } if (exists $starrez{$key}{"RA"}) { } else { $starrez{$key}{"RA"} = "None"; } if (exists $explanation{$key}) { } else { $explanation{$key} = "None"; } my $temp_key = $starrez{$key}{"dorm"}; if ($starrez{$key}{"greek"} ne "None") { $temp_key = $temp_key . "\|$starrez{$key}{greek}"; } my $temp_semester = $semester; if ($starrez{$key}{"RA"} ne "None") { $temp_semester = "RA\-" . $temp_semester; } if (defined $flag_assignments{$temp_key}) { print "KEY [$key] TK [$temp_key] TS [$temp_semester] FAS [$fla +g_assignments{$temp_key}{starrez}] FAA [$flag_assignments{$temp_key}{ +abbreviation}]\n"; } # ONLY ONE FLAGE PER CATEGORY, AND GREEKS LIVING ON CAMPUS WILL AL +SO GET NR ACCESS TO THE HOUSE OF THE FRAT/SORORITY if ($starrez{$key}{"dorm"} ne "None") { if ($flag_assignments{$temp_key}{$temp_semester} ne "") { if (($flag_assignments{$temp_key}{$temp_semester} ne "x") +and ($flag_assignments{$temp_key}{$temp_semester} ne "None")) { if ($starrez{$key}{"RA"} ne "None") { # Patron is an RA or CRA so needs appropriate acce +ss if (exists $output{$key}) { $output{$key} = $output{$key} . ",P$flag_assig +nments{$temp_key}{$temp_semester}"; } else { $output{$key} = "C|$key|$flag_assignments{$tem +p_key}{abbreviation},(P$flag_assignments{$temp_key}{$temp_semester}"; } } else { # Patron is not an RA or CRA so will just receive +normal access if (exists $output{$key}) { $output{$key} = $output{$key} . ",P$flag_assig +nments{$temp_key}{$temp_semester}"; } else { $output{$key} = "C|$key|$flag_assignments{$tem +p_key}{abbreviation},(P$flag_assignments{$temp_key}{$temp_semester}"; } } } } else { #print "TK [$temp_key]\n"; if ($temp_key =~ '|') { my @temp_1 = split('|',$temp_key); # Give access to their dorm if (exists $output{$key}) { $output{$key} = $output{$key} . ",P$flag_assignmen +ts{$temp_1[0]}{$temp_semester}"; } else { $output{$key} = "C|$key|$flag_assignments{$temp_1[ +0]}{abbreviation},(P$flag_assignments{$temp_1[0]}{$temp_semester}"; } # Find which house their Greek affiliation is in and g +ive them Non-Res (NR) access for my $key2 (sort keys %flag_assignments) { print "KEY2 [$key2]\n"; if (defined $flag_assignments{$key2}{"greek"} ne " +") { if ($temp_1[1] eq $flag_assignments{$key2}{"gr +eek"}) { my $temp2semester = "NR-" . $semester; if ($flag_assignments{$key2}{"$temp2semest +er"} ne "") { if (exists $output{$key}) { print "KEY [$key] NR-$semester [$f +lag_assignments{$key2}{$temp2semester}]\n"; $output{$key} = $output{$key} . ", +P$flag_assignments{$key2}{$temp2semester}"; } } else { print BADOUTPUT "No NR flag,$key,$star +rez{$key}{dorm},$starrez{$key}{greek},$starrez{$key}{RA}\n"; } } } else { #print "TEMP_KEY [$temp_key]\n"; } } } else { print BADOUTPUT "Not Greek and should be,$key,$starrez +{$key}{dorm},$starrez{$key}{greek},$starrez{$key}{RA}\n"; } } } }
I am hoping to find where or how I am adding keys to the %flag_assignments hash. I didn't think that would be too tough, but I cannot find it, so I am asking for some help. Thanks.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Not meaning to add values to a hash ("autovivification")
by Corion (Patriarch) on Dec 21, 2012 at 16:06 UTC | |
by stu96art (Scribe) on Dec 21, 2012 at 16:44 UTC | |
by Corion (Patriarch) on Dec 21, 2012 at 17:01 UTC | |
by stu96art (Scribe) on Dec 21, 2012 at 17:29 UTC | |
Re: Not meaning to add values to a hash
by tobyink (Canon) on Dec 21, 2012 at 16:06 UTC | |
by stu96art (Scribe) on Dec 21, 2012 at 16:56 UTC | |
by muba (Priest) on Jan 02, 2013 at 14:15 UTC | |
Re: Not meaning to add values to a hash
by flexvault (Monsignor) on Dec 22, 2012 at 14:18 UTC | |
Re: Not meaning to add values to a hash
by Athanasius (Archbishop) on Dec 22, 2012 at 16:29 UTC |
Back to
Seekers of Perl Wisdom