Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 12/29/2016
- # To check for errors use: perl -c pgm.pl
- use strict;
- use warnings;
- my %emphrshash;
- my $empid='ME';
- my $actcode='0550';
- my $job='101200';
- my $esthrs=5.0;
- $emphrshash{$empid}{$actcode}{$job}=10; # Put in starting value.
- my $t=$emphrshash{$empid}{$actcode}{$job};
- print "Old Value=$t\n";
- my $z=hashadd3dpos2(\%emphrshash,$empid,$actcode,$job,0,$esthrs);
- $t=$emphrshash{$empid}{$actcode}{$job};
- print "New Value=$t\n";
- exit 0; # Exit main pgm.
- ###########################################################################
- # This subroutine has a string of parts as a hash value. Each part
- # is separated by a tab, which can later be split into an array.
- # This subroutine adds a numeric value to the $ppos position in the string
- # in the hash value.
- # Example:
- # Data for $hash{one}{two}{three} is:0.1<TAB>10
- # Add number to pos 1 (second position)
- # $z=hashadd3dpos2(\%hash,'one','two','three',1,5);
- # Resulting value for $hash{one}{two}{three} is:0.1<TAB>15
- sub hashadd3dpos2
- {my($href,$pkk1,$pkk2,$pkk3,$ppos,$pval)=@_;
- my($out,$s,$t);
- my(@a);
- my $procname="hashadd3dpos2";
- # Put data validation here later.
- # Now add value to position $ppos.
- $out=$pval;
- $t=%{$href{$pkk1}{$pkk2}{$pkk3}}; # COMPILE ERROR HERE
- if (exists %{$href{$pkk1}{$pkk2}{$pkk3}} ) # ERROR ALSO HERE
- {
- $t=%{$href{$pkk1}{$pkk2}{$pkk3}}; # add existing value
- @a=split($SEP,$t);
- $a[$ppos]=$a[$ppos]+$pval;
- $out=join($SEP,@a);
- %{$href{$pkk1}{$pkk2}{$pkk3}}=$out;
- }
- else {
- $a[$ppos]=$pval;
- @a=convundefarr(\@a);
- $out=join($SEP,@a);
- %{$href{$pkk1}{$pkk2}{$pkk3}}=$out; # Create New value
- }
- return $out; # hashadd3dpos
- }
Add Comment
Please, Sign In to add comment