$s = join('|',
map { local $_=$_; s/\^/^1/g; s/\|/^2/g; $_ }
%test_hash
);
####
%test_hash = map { local $_=$_; s/\^1/^/g; s/\^2/|/g; $_ }
split(/\|/, $s);
####
use Data::Dumper ();
%test_hash = (
'apple' => 'red',
'lime' => 'green',
'junk' => 'foo^bar',
'junk2' => 'bla|bla',
);
print(Data::Dumper->Dump([ \%test_hash ],[qw( $test_hash_ref )]));
print("\n");
$s = join('|',
map { local $_=$_; s/\^/^1/g; s/\|/^2/g; $_ }
%test_hash
);
print($s, "\n");
print("\n");
%test_hash = map { local $_=$_; s/\^1/^/g; s/\^2/|/g; $_ }
split(/\|/, $s);
print(Data::Dumper->Dump([ \%test_hash ],[qw( $test_hash_ref )]));
__END__
output
======
$test_hash_ref = {
'apple' => 'red',
'junk' => 'foo^bar',
'junk2' => 'bla|bla',
'lime' => 'green'
};
apple|red|junk|foo^1bar|junk2|bla^2bla|lime|green
$test_hash_ref = {
'apple' => 'red',
'junk' => 'foo^bar',
'lime' => 'green',
'junk2' => 'bla|bla'
};