Guest User

Untitled

a guest
May 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. ################################# HELPERS ###################################
  2.  
  3. ###############################################################################
  4. ## Function : unmarshal ( )
  5. ## ----------------------------------------------------------------------------
  6. ## Description :
  7. ## unserialize transform array into hash, but keys are not ordered anymore
  8. ## unmarshal does the unserialize, reorder and return an array
  9. ## Parameters :
  10. ## Return :
  11. ###############################################################################
  12. sub unmarshal {
  13. my $AA = shift;
  14. my @CC = ();
  15. my $BB_ref = unserialize($AA);
  16. my @BB_keys = sort keys %$BB_ref;
  17. foreach(@BB_keys) {
  18. push @CC, $BB_ref->{$_};
  19. }
  20. return @CC;
  21. }
  22.  
  23. ###############################################################################
  24. ## Function : unmarshal2 ( )
  25. ## ----------------------------------------------------------------------------
  26. ## Description :
  27. ## same as unmarshal but with depth 2
  28. ## Parameters :
  29. ## Return :
  30. ###############################################################################
  31. sub unmarshal2 {
  32. my $AA = shift;
  33. my @CC = ();
  34. my $BB_ref = unserialize($AA);
  35. my @BB_keys = sort keys %$BB_ref;
  36. foreach(@BB_keys) {
  37. my @DD = ();
  38. my $values_ref = $BB_ref->{$_};
  39. my @values_keys = sort keys %$values_ref;
  40. foreach(@values_keys) {
  41. push @DD, $values_ref->{$_};
  42. }
  43. push @CC, [@DD];
  44. }
  45.  
  46. return @CC;
  47. }
Add Comment
Please, Sign In to add comment