Skip to content

Instantly share code, notes, and snippets.

@jevinskie
Created July 8, 2010 19:04
Show Gist options
  • Save jevinskie/468443 to your computer and use it in GitHub Desktop.
Save jevinskie/468443 to your computer and use it in GitHub Desktop.
################################# HELPERS ###################################
###############################################################################
## Function : unmarshal ( )
## ----------------------------------------------------------------------------
## Description :
## unserialize transform array into hash, but keys are not ordered anymore
## unmarshal does the unserialize, reorder and return an array
## Parameters :
## Return :
###############################################################################
sub unmarshal {
my $AA = shift;
my @CC = ();
my $BB_ref = unserialize($AA);
my @BB_keys = sort keys %$BB_ref;
foreach(@BB_keys) {
push @CC, $BB_ref->{$_};
}
return @CC;
}
###############################################################################
## Function : unmarshal2 ( )
## ----------------------------------------------------------------------------
## Description :
## same as unmarshal but with depth 2
## Parameters :
## Return :
###############################################################################
sub unmarshal2 {
my $AA = shift;
my @CC = ();
my $BB_ref = unserialize($AA);
my @BB_keys = sort keys %$BB_ref;
foreach(@BB_keys) {
my @DD = ();
my $values_ref = $BB_ref->{$_};
my @values_keys = sort keys %$values_ref;
foreach(@values_keys) {
push @DD, $values_ref->{$_};
}
push @CC, [@DD];
}
return @CC;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment