Hi monks i want to replace a hash keys against another hash value this is my code

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use XML::Simple; my %xhash=('chapter' => { ############################################################ 'subchap1' => ##[## { 'head1' => 'Introduction and Hi +story', 'para' => "Their place in textb +ooks of neuropsychopharmacology was a long time in coming. Although i +t has been known for more than 80 years that adenosine and ATP can el +icit potent pharmacological effects on the cardiovascular system (Dru +ry and Szent-Gyorgy, 1929), studies of their effects on the brain or +peripheral nerves by central or systemic injection lagged approximate +ly 20 years. The evidence that endogenous purines regulated the activ +ity of the nervous system was not widely accepted until the 1990s whe +n molecular cloning of the receptors for adenosine and ATP revealed t +hat, like the other transmitters discussed in this book, there was ce +llular and regional selectivity in their expression sites in the brai +n, expanding their more general roles in energy metabolism to include + additional intercellular signaling functions. Subsequent research on + the purinergic systems of the central nervous system has established + two main categories of signal transduction: sites where adenosine is + the mediator (A receptors; Table 11\x{2013}1) and sites where ATP (a +nd sometimes UTP) is the mediator, often in conjunction with either a + monoamine or a neuropeptide. Subsequent work on the receptors for ad +enosine as a special kind of intercellular signal, a neuromodulator, +but not a classic neurotransmitter, and for ATP as a cotransmitter mo +re firmly established their different physiological roles and the pha +rmacological roles each system has been found to play in the brain as + well as the autonomic nervous system." }, { 'head1' => 'Neurosteroids', 'para' => [ { 'content' => [ 'Acc +ording to their discoverer, Etienne Baulieu, neurosteroids are those +steroids that are synthesized in the nervous system either ', ' fr +om cholesterol or by ', ' me +tabolism of blood-borne precursors but are found at levels in the ner +vous system that are independent of steroid synthesis by adrenals or +gonads. Such steroids include at least two previously known steroid p +recursors, pregnenalone (PREG) and dehydroepiandrosterone (DHEA), tha +t in the nervous system have effects alone or as sulfated esters. In +the central and peripheral nervous systems, neurosteroid synthesis ha +s been attributed to oligodendrocytes, astrocytes, and neurons. The p +eripheral benzodiazepine receptor found on the mitochondrial outer me +mbrane has been suggested to allow cholesterol access to the P450 cle +avage enzyme complex on the inner mitochondrial membrane, leading to +PREG formation and subsequently to other neurosteroids (', ').' ], 'hotlink' => { 'xref' + => { + 'xref' => 'f012003', + 'xidtype' => 'figure' + }, 'conte +nt' => "Fig. 12\x{2013}3" }, 'emphasis' => [ { 'co +ntent' => 'de novo', 'st +yle' => 'it' }, { 'co +ntent' => 'in situ', 'st +yle' => 'it' } ] }, { 'c' => "\x{3b4}", 'sub' => 'A', 'content' => [ 'In +contrast to the endocrine actions of adrenal steroids on the brain, a +cting at a distance and at very low concentrations, neurosteroids are + thought to act locally as either autocrine (acting on the cells that + synthesizes them) or paracrine (acting on cells close to the site of + synthesis) signals. In this manner, the ability to activate myelin s +ynthesis in oligodendrocytes may provide a reparative effect in multi +ple sclerosis. In their sulfated ester forms, both PREG and DHEA have + been reported to be potent regulators of GABA', ' an +d NMDA receptor functions, with PREG-S and DHEA-S inhibiting the effe +cts of GABA; however, these effects on the GABA receptor are reduced +if the complex contains a ', ' su +bunit.' ] }, { 'c' => [ "\x{3b1}", "\x{3b1}", "\x{3b1}", "\x{3b2}", "\x{3b1}", "\x{3b2}", "\x{3b1}", "\x{3b1}", "\x{3b1}", "\x{3b1}", "\x{3b1}", "\x{3b2}", "\x{3b1}", "\x{3b1}", "\x{3b1}", "\x{3b2}" ], 'content' => [ 'In +addition, further characterization of the neurosteroids suggests that + a small group of pregnenolone-, progesterone-, or tetrahydrodeoxycor +ticosterone-derived catabolites are the active moieties in the CNS, n +amely 3', ',5' +, '- a +nd 3', ',5' +, '-an +drosterone, 3', ',5' +, '-TH +P pregnenolone, 3', ',5' +, '-TH +P allopregnenolone, 3', ',5' +, '-TH +DOC allotetrahydroDOC, 3', ',5' +, '-TH +DOC tetrahydroDOC, and 3', ',5' +, '- a +nd 3', ',5' +, '-an +drostanol (Morrow, 2007). These are the neurosteroids that are believ +ed to be responsible for the largely GABA-enhancing actions to induce + anxiolytic, sedative, and anticonvulsant activity through allosteric + modifications at discrete sites on the receptor. Of interest is that + systemic doses of ethanol at low to moderate pharmacological levels +induce elevation of neurosteroids to levels capable of modifying GABA + receptors and contributing to the cellular and behavioral effects of + ethanol (see ', ').' ], 'hotlink' => { 'xref' + => { + 'xref' => 'c018', + 'xidtype' => 'text' + }, 'conte +nt' => 'Chapter 18' } } ] } ], 'para' => { 'c' => [ '\'', '\'' ], 'sub' => '1', 'content' => [ 'P2Y receptor antagoni +sts have been proposed as potential neuroprotective agents in the bra +in by modulation of Glu-induced currents at AMPA receptors and by exc +essive activation of glutamate receptor systems generically implicate +d in the apoptotic cellular death associated with stroke, epileptic s +eizures, and neurodegenerative diseases such as Alzheimer', 's disease, Parkinson' +, 's disease, and amyotr +ophic lateral sclerosis. Endogenous ATP has been claimed to be involv +ed in the regulation of anxiety via stimulation of P2Y', ' receptors in the dor +somedial hypothalamus in rats. Currently, none of these therapeutic e +ntities are known to be in the developmental pipeline.' ##]## ############################################################ }, 'title' => '11 Purinergic Pharmacology', 'id' => 'c011', 'chapnum' => '11' } ); my %c_hash=('chapter' => { 'addval' => { '[subchap1' => { 'addval' => { +'head1' => { + 'addval' => {}, + 'repval' => 'h1' + }, +'para' => { + 'addval' => { + 'c' => { + 'addval' => {}, + 'repval' => 'char' + } + }, + 'repval' => 'p' + } }, 'repval' => 's +ubsec1' }, 'para' => { 'addval' => {}, 'repval' => 'subsec +p' } }, 'repval' => 'section' }, 'chapnum' => { 'addval' => { 'id' => { 'addval' => {}, 'repval' => 'cid' }, 'title' => { 'addval' => {}, 'repval' => 'head' } }, 'repval' => 'secnum' } ); my %repl; # lookup table: a => 1, etc. traverse(\%c_hash, sub { my ($key, $val) = @_; $repl{$key} = $val; }, "collect" ); # print Dumper \%repl; # debug traverse(\%xhash, sub { my ($key, $val, $href) = @_; if (exists $repl{$key}) { my $newkey = $repl{$key}; $href->{$newkey} = $val; delete $href->{$key}; } }, "replace" ); print Dumper (\%xhash); sub traverse { my ($hash, $callback, $mode) = @_; return unless ref($hash) eq "HASH"; for my $key (keys %$hash) { my $val = $hash->{$key}; if (ref($val) eq "HASH") { traverse($val, $callback, $mode); if ($mode eq "collect") { if (exists $val->{repval}) { $callback->($key, $val->{repval}); } } } if ($mode eq "replace") { $callback->($key, $val, $hash); } } } sub recur($) { my $arrRef = $_[0]; my @procArr = @$arrRef; my $assign = ''; my %c_hash = (); my @tmpArr = @procArr; shift(@tmpArr); my $arr = $procArr[0]; if ($arr=~m/\[(.*?)\=(.*)\]/ig) { $assign = $1; my $tmpVal = ''; $tmpVal = $2; $tmpVal =~ s/\=(.*?)/$1/ig; $c_hash{$assign}{'repval'} = $tmpVal; ($c_hash{$assign}{'addval'},@tmpArr) = recur(\@tmpArr); $arr = shift(@tmpArr); if ($arr) { if ($arr=~m/\[(.*?)\=(.*)\]/ig) { my $key = $1; my $tmpVal = ''; $tmpVal = $2; $tmpVal =~ s/\=(.*?)/$1/ig; $c_hash{$key}{'repval'} = $tmpVal; ($c_hash{$key}{'addval'},@tmpArr) = recur(\@tmpArr +); $arr = shift(@tmpArr); } } } return (\%c_hash, @tmpArr); }

xhash keys are replaced against same key values in $c_hash{replval} this are my outputs and my expected output also defined

_OUTPUT_ $VAR1 = { 'section' => { ############################################################ 'subchap1' => ###[ { 'head1' => 'Introduction an +d History', 'para' => "Their place in t +extbooks of neuropsychopharmacology was a long time in coming. Althou +gh it has been known for more than 80 years that adenosine and ATP ca +n elicit potent pharmacological effects on the cardiovascular system +(Drury and Szent-Gyorgy, 1929), studies of their effects on the brain + or peripheral nerves by central or systemic injection lagged approxi +mately 20 years. The evidence that endogenous purines regulated the a +ctivity of the nervous system was not widely accepted until the 1990s + when molecular cloning of the receptors for adenosine and ATP reveal +ed that, like the other transmitters discussed in this book, there wa +s cellular and regional selectivity in their expression sites in the +brain, expanding their more general roles in energy metabolism to inc +lude additional intercellular signaling functions. Subsequent researc +h on the purinergic systems of the central nervous system has establi +shed two main categories of signal transduction: sites where adenosin +e is the mediator (A receptors; Table 11\x{2013}1) and sites where AT +P (and sometimes UTP) is the mediator, often in conjunction with eith +er a monoamine or a neuropeptide. Subsequent work on the receptors fo +r adenosine as a special kind of intercellular signal, a neuromodulat +or, but not a classic neurotransmitter, and for ATP as a cotransmitte +r more firmly established their different physiological roles and the + pharmacological roles each system has been found to play in the brai +n as well as the autonomic nervous system." }, { 'head1' => 'Neurosteroids', 'para' => [ { 'content' => +[ + 'According to their discoverer, Etienne Baulieu, neurosteroids are +those steroids that are synthesized in the nervous system either ', + ' from cholesterol or by ', + ' metabolism of blood-borne precursors but are found at levels in t +he nervous system that are independent of steroid synthesis by adrena +ls or gonads. Such steroids include at least two previously known ste +roid precursors, pregnenalone (PREG) and dehydroepiandrosterone (DHEA +), that in the nervous system have effects alone or as sulfated ester +s. In the central and peripheral nervous systems, neurosteroid synthe +sis has been attributed to oligodendrocytes, astrocytes, and neurons. + The peripheral benzodiazepine receptor found on the mitochondrial ou +ter membrane has been suggested to allow cholesterol access to the P4 +50 cleavage enzyme complex on the inner mitochondrial membrane, leadi +ng to PREG formation and subsequently to other neurosteroids (', + ').' +], 'emphasis' => + [ + { + 'style' => 'it', + 'content' => 'de novo' + }, + { + 'style' => 'it', + 'content' => 'in situ' + } + ], 'hotlink' => +{ + 'xref' => { + 'xref' => 'f012003', + 'xidtype' => 'figure' + }, + 'content' => "Fig. 12\x{2013}3" +} }, { 'c' => "\x{3b +4}", 'sub' => 'A', 'content' => +[ + 'In contrast to the endocrine actions of adrenal steroids on the br +ain, acting at a distance and at very low concentrations, neurosteroi +ds are thought to act locally as either autocrine (acting on the cell +s that synthesizes them) or paracrine (acting on cells close to the s +ite of synthesis) signals. In this manner, the ability to activate my +elin synthesis in oligodendrocytes may provide a reparative effect in + multiple sclerosis. In their sulfated ester forms, both PREG and DHE +A have been reported to be potent regulators of GABA', + ' and NMDA receptor functions, with PREG-S and DHEA-S inhibiting th +e effects of GABA; however, these effects on the GABA receptor are re +duced if the complex contains a ', + ' subunit.' +] }, { 'c' => [ "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b2}", "\x{ +3b1}", "\x{ +3b2}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b2}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b2}" ], 'content' => +[ + 'In addition, further characterization of the neurosteroids suggest +s that a small group of pregnenolone-, progesterone-, or tetrahydrode +oxycorticosterone-derived catabolites are the active moieties in the +CNS, namely 3', + ',5', + '- and 3', + ',5', + '-androsterone, 3', + ',5', + '-THP pregnenolone, 3', + ',5', + '-THP allopregnenolone, 3', + ',5', + '-THDOC allotetrahydroDOC, 3', + ',5', + '-THDOC tetrahydroDOC, and 3', + ',5', + '- and 3', + ',5', + '-androstanol (Morrow, 2007). These are the neurosteroids that are +believed to be responsible for the largely GABA-enhancing actions to +induce anxiolytic, sedative, and anticonvulsant activity through allo +steric modifications at discrete sites on the receptor. Of interest i +s that systemic doses of ethanol at low to moderate pharmacological l +evels induce elevation of neurosteroids to levels capable of modifyin +g GABA receptors and contributing to the cellular and behavioral effe +cts of ethanol (see ', + ').' +], 'hotlink' => +{ + 'xref' => { + 'xref' => 'c018', + 'xidtype' => 'text' + }, + 'content' => 'Chapter 18' +} } ] } ##]##, ############################################################ 'head' => '11 Purinergic Pharmacology', 'subsecp' => { 'sub' => '1', 'char' => [ '\'', '\'' ], 'content' => [ 'P2Y receptor a +ntagonists have been proposed as potential neuroprotective agents in +the brain by modulation of Glu-induced currents at AMPA receptors and + by excessive activation of glutamate receptor systems generically im +plicated in the apoptotic cellular death associated with stroke, epil +eptic seizures, and neurodegenerative diseases such as Alzheimer', 's disease, Par +kinson', 's disease, and + amyotrophic lateral sclerosis. Endogenous ATP has been claimed to be + involved in the regulation of anxiety via stimulation of P2Y', ' receptors in +the dorsomedial hypothalamus in rats. Currently, none of these therap +eutic entities are known to be in the developmental pipeline.' ] }, 'cid' => 'c011', 'secnum' => '11' } }; _EXPECTED OUTPUT_ $VAR1 = { 'section' => { ############################################################ 'subsec1' => ##[## { 'h1' => 'Introduction and H +istory', 'p' => "Their place in text +books of neuropsychopharmacology was a long time in coming. Although +it has been known for more than 80 years that adenosine and ATP can e +licit potent pharmacological effects on the cardiovascular system (Dr +ury and Szent-Gyorgy, 1929), studies of their effects on the brain or + peripheral nerves by central or systemic injection lagged approximat +ely 20 years. The evidence that endogenous purines regulated the acti +vity of the nervous system was not widely accepted until the 1990s wh +en molecular cloning of the receptors for adenosine and ATP revealed +that, like the other transmitters discussed in this book, there was c +ellular and regional selectivity in their expression sites in the bra +in, expanding their more general roles in energy metabolism to includ +e additional intercellular signaling functions. Subsequent research o +n the purinergic systems of the central nervous system has establishe +d two main categories of signal transduction: sites where adenosine i +s the mediator (A receptors; Table 11\x{2013}1) and sites where ATP ( +and sometimes UTP) is the mediator, often in conjunction with either +a monoamine or a neuropeptide. Subsequent work on the receptors for a +denosine as a special kind of intercellular signal, a neuromodulator, + but not a classic neurotransmitter, and for ATP as a cotransmitter m +ore firmly established their different physiological roles and the ph +armacological roles each system has been found to play in the brain a +s well as the autonomic nervous system." }, { 'h1' => 'Neurosteroids', 'p' => [ { 'content' => +[ + 'According to their discoverer, Etienne Baulieu, neurosteroids are +those steroids that are synthesized in the nervous system either ', + ' from cholesterol or by ', + ' metabolism of blood-borne precursors but are found at levels in t +he nervous system that are independent of steroid synthesis by adrena +ls or gonads. Such steroids include at least two previously known ste +roid precursors, pregnenalone (PREG) and dehydroepiandrosterone (DHEA +), that in the nervous system have effects alone or as sulfated ester +s. In the central and peripheral nervous systems, neurosteroid synthe +sis has been attributed to oligodendrocytes, astrocytes, and neurons. + The peripheral benzodiazepine receptor found on the mitochondrial ou +ter membrane has been suggested to allow cholesterol access to the P4 +50 cleavage enzyme complex on the inner mitochondrial membrane, leadi +ng to PREG formation and subsequently to other neurosteroids (', + ').' +], 'emphasis' => + [ + { + 'style' => 'it', + 'content' => 'de novo' + }, + { + 'style' => 'it', + 'content' => 'in situ' + } + ], 'hotlink' => +{ + 'xref' => { + 'xref' => 'f012003', + 'xidtype' => 'figure' + }, + 'content' => "Fig. 12\x{2013}3" +} }, { 'cap' => "\x{ +3b4}", 'sub' => 'A', 'content' => +[ + 'In contrast to the endocrine actions of adrenal steroids on the br +ain, acting at a distance and at very low concentrations, neurosteroi +ds are thought to act locally as either autocrine (acting on the cell +s that synthesizes them) or pcrine (acting on cells close to the site + of synthesis) signals. In this manner, the ability to activate myeli +n synthesis in oligodendrocytes may provide a reptive effect in multi +ple sclerosis. In their sulfated ester forms, both PREG and DHEA have + been reported to be potent regulators of GABA', + ' and NMDA receptor functions, with PREG-S and DHEA-S inhibiting th +e effects of GABA; however, these effects on the GABA receptor are re +duced if the complex contains a ', + ' subunit.' +] }, { 'cap' => [ "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b2}", "\x{ +3b1}", "\x{ +3b2}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b2}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b1}", "\x{ +3b2}" ], 'content' => +[ + 'In addition, further characterization of the neurosteroids suggest +s that a small group of pregnenolone-, progesterone-, or tetrahydrode +oxycorticosterone-derived catabolites are the active moieties in the +cNS, namely 3', + ',5', + '- and 3', + ',5', + '-androsterone, 3', + ',5', + '-THP pregnenolone, 3', + ',5', + '-THP allopregnenolone, 3', + ',5', + '-THDOc allotetrahydroDOc, 3', + ',5', + '-THDOc tetrahydroDOc, and 3', + ',5', + '- and 3', + ',5', + '-androstanol (Morrow, 2007). These are the neurosteroids that are +believed to be responsible for the largely GABA-enhancing actions to +induce anxiolytic, sedative, and anticonvulsant activity through allo +steric modifications at discrete sites on the receptor. Of interest i +s that systemic doses of ethanol at low to moderate pharmacological l +evels induce elevation of neurosteroids to levels capable of modifyin +g GABA receptors and contributing to the cellular and behavioral effe +cts of ethanol (see ', + ').' +], 'hotlink' => +{ + 'xref' => { + 'xref' => 'c018', + 'xidtype' => 'text' + }, + 'content' => 'chapter 18' +} } ] } ## ]##, ############################################################ 'head' => '11 Purinergic Pharmacology', 'subsecp' => { 'sub' => '1', 'char' => [ '\'', '\'' ], 'content' => [ 'P2Y receptor a +ntagonists have been proposed as potential neuroprotective agents in +the brain by modulation of Glu-induced currents at AMPA receptors and + by excessive activation of glutamate receptor systems generically im +plicated in the apoptotic cellular death associated with stroke, epil +eptic seizures, and neurodegenerative diseases such as Alzheimer', 's disease, Par +kinson', 's disease, and + amyotrophic lateral sclerosis. Endogenous ATP has been claimed to be + involved in the regulation of anxiety via stimulation of P2Y', ' receptors in +the dorsomedial hypothalamus in rats. currently, none of these therap +eutic entities are known to be in the developmental pipeline.' ] }, 'cid' => 'c011', 'secnum' => '11' } };

see the input output where i marked in between the brackets the contents could not change please help me to debug the error


In reply to Please debug this code by satzbu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.