#!/bin/ksh93 # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r714 src/43haes/lib/ksh93/util/list/KLIB_UTIL_LIST_hasharray_datadumper.sh 1.4 # # Licensed Materials - Property of IBM # # Restricted Materials of IBM # # COPYRIGHT International Business Machines Corp. 2005,2011 # All Rights Reserved # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with IBM Corp. # # IBM_PROLOG_END_TAG # @(#)12 1.4 src/43haes/lib/ksh93/util/list/KLIB_UTIL_LIST_hasharray_datadumper.sh, hacmp, 61haes_r714 11/28/11 15:13:43 # #=head1 NAME # # KLIB_UTIL_LIST_hasharray_datadumper - Similar to the perl Data::Dumper module, dumps ksh93 hash # tables as sourceable strings # #=head1 SYNOPSIS # # typeset -A data # array(\ # [test]="foo" # [bar]="123" # ) # # KLIB_UTIL_LIST_hasharray_datadumper data # # #=head1 DESCRIPTION # # Dumps ksh93 hash tables as strings that can then be sourced by another script # to internalize, used for persisting data between ksh93 sessions # #=head1 ARGUMENTS # # 1: [by ref] array to dump # #=head1 RETURN # # None # #=head1 COPYRIGHT # #(C) COPYRIGHT International Business Machines Corp. 2005 #All Rights Reserved # #=cut # function KLIB_UTIL_LIST_hasharray_datadumper { . /usr/es/lib/ksh93/func_include typeset -n array=$1 if (( ${#array[*]} == 0 )); then return 1 fi echo echo "unset ${!array}" echo "typeset -A ${!array}" echo "${!array}=( \\" for key in ${!array[*]}; do echo "\t[$key]=\"${array[$key]}\"" done echo ")" echo return 0 }