daily pastebin goal
32%
SHARE
TWEET

Perl3dhash

bulrush Dec 29th, 2016 (edited) 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # 12/29/2016
  2. # To check for errors use: perl -c pgm.pl
  3.  
  4. use strict;
  5. use warnings;
  6.  
  7. my %emphrshash;
  8. my $empid='ME';
  9. my $actcode='0550';
  10. my $job='101200';
  11. my $esthrs=5.0;
  12. $emphrshash{$empid}{$actcode}{$job}=10; # Put in starting value.
  13. my $t=$emphrshash{$empid}{$actcode}{$job};
  14. print "Old Value=$t\n";
  15.  
  16.  
  17. my $z=hashadd3dpos2(\%emphrshash,$empid,$actcode,$job,0,$esthrs);
  18. $t=$emphrshash{$empid}{$actcode}{$job};
  19. print "New Value=$t\n";
  20.  
  21. exit 0;  # Exit main pgm.
  22. ###########################################################################
  23. # This subroutine has a string of parts as a hash value. Each part
  24. # is separated by a tab, which can later be split into an array.
  25. # This subroutine adds a numeric value to the $ppos position in the string
  26. # in the hash value.
  27. # Example:
  28. # Data for $hash{one}{two}{three} is:0.1<TAB>10
  29. # Add number to pos 1 (second position)
  30. # $z=hashadd3dpos2(\%hash,'one','two','three',1,5);
  31. # Resulting value for $hash{one}{two}{three} is:0.1<TAB>15
  32.  
  33. sub hashadd3dpos2
  34. {my($href,$pkk1,$pkk2,$pkk3,$ppos,$pval)=@_;
  35. my($out,$s,$t);
  36. my(@a);
  37.  
  38. my $procname="hashadd3dpos2";
  39.  
  40. # Put data validation here later.
  41.  
  42. # Now add value to position $ppos.
  43. $out=$pval;
  44. $t=%{$href{$pkk1}{$pkk2}{$pkk3}}; # COMPILE ERROR HERE
  45. if (exists %{$href{$pkk1}{$pkk2}{$pkk3}} ) # ERROR ALSO HERE
  46.     {
  47.     $t=%{$href{$pkk1}{$pkk2}{$pkk3}}; # add existing value
  48.     @a=split($SEP,$t);
  49.     $a[$ppos]=$a[$ppos]+$pval;
  50.     $out=join($SEP,@a);
  51.     %{$href{$pkk1}{$pkk2}{$pkk3}}=$out;
  52.     }
  53. else {
  54.     $a[$ppos]=$pval;
  55.     @a=convundefarr(\@a);
  56.     $out=join($SEP,@a);
  57.     %{$href{$pkk1}{$pkk2}{$pkk3}}=$out; # Create New value
  58.     }
  59.  
  60. return $out; # hashadd3dpos
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top