dear monks i want to move some lines in an xml file

<?xml version="1.0" encoding="UTF-8"?> <sec><title>The Impact of Aerosols</title> <p>The impact of aerosols on our daily lives is large, as our activiti +es are performed in an atmospheric sea containing gases and particles + (<xref ref-type="table" rid="ch1-t001">Table 1.1</xref>). The partic +les, liquid and solid, organic and inorganic, viable and nonviable, i +nfluence the environment. Natural particle phenomena include cloud fo +rmation, the role of particles in the water cycle, the shaping of lan +d by wind, pollination of plants, and the distribution of seeds and s +pores. Human uses of aerosols include the atomization of fuels prior +to combustion, the application of paints, cosmetics, medicines, insec +ticides, and lubricants; and scientific uses.</p> <p>Unfortunately, aerosols often cause problems which resist eradicati +on. Among these are infectious diseases including the common cold, in +fluenza, viral pneumonia, measles, mumps, and tuberculosis. Other dis +eases in which inhaled particles often play a central role are bronch +itis, pulmonary emphysema, asthma, diffuse interstitial fibrosis, alv +eolitis, silicosis, anthracosilicosis, berylliosis, farmers lung, bys +sinossis, lung cancer, and nasal cancer.</p> <sec><title>Size Regimes</title> <p>The great diversity in particle size, shape, and composition makes +it impossible to describe aerosol behavior simply. As a starting poin +t, one can divide aerosols into <italic>regimes</italic> (<xref ref-t +ype="table" rid="ch1-t002">Table 1.2</xref>). These regimes, which en +compass given size ranges, are each associated with sets of equations + that describe the physical behavior of aerosols. An important dimens +ionless parameter, the <italic>Knudsen number</italic>, Kn, which rel +ates the particle radius, r<sub>p</sub>, to the molecular mean free-p +ath of the suspending gas, <italic>&lambda;</italic>g, is given by:</ +p> <disp-formula id="ch1equ-001"><tex-math><?TeX \begin{equation}<$$>{\rm +{Kn}} = {{{\lambda _{\rm{g}}}} \over {{{\rm{r}}_{\rm{p}}}}}<$$>\end{e +quation}?></tex-math><graphic xmlns:xlink="http://www.w3.org/1999/xli +nk" xlink:href="ch1equ-001.gif"/></disp-formula> <p><bold>Cloud</bold>&mdash;Any free (not spatially confined) aerosol +system with a definite overall shape and size. Rain clouds and smoke +rings are examples.</p> <p><bold>Colloid</bold>&mdash;A dispersion of liquid or solid particle +s in a gas, liquid, or solid medium that has all of the following pro +perties: slow settling, large surface to volume ratio, invisibility t +o the unaided eye, and producing scattering of a light beam. Examples + include smoke, milk, and gelatin.</p> <p>Several reference books on aerosols have been published. The basic +theoretical reference is a work by Nicholai A. Fuchs (1964) entitled +<italic>The Mechanics of Aerosols</italic>, which was translated from + Russian into English by R.E. Daisley and Marina Fuchs and edited by +C.N. Davies. A variety of additional books, some general and some spe +cialized, are presented in <xref ref-type="table" rid="ch1-t003">Tabl +e 1.3</xref>. Although not exhaustive, the listed references cover mo +st problems that arise in studies with aerosols.</p></sec></sec> <table-wrap id="ch1-t001" position="float"><label>Table 1.1<x> </x></l +abel><caption><p></bold> Some Particles Commonly Found in Air, Their +Sizes and Impacts on Natural Phenomena and Human Health </caption><gr +aphic xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="ch1t001. +gif"/></table-wrap> <table-wrap id="ch1-t002" position="float"><label>Table 1.2<x> </x></l +abel><caption><p></bold> The Major Particle Regimes and the Dependenc +e of Various Properties on Particle Radius </caption><graphic xmlns:x +link="http://www.w3.org/1999/xlink" xlink:href="ch1t002.gif"/></table +-wrap> <table-wrap id="ch1-t003" position="float"><label>Table 1.3<x> </x></l +abel><caption><p></bold> Selected References on Aerosols </caption><g +raphic xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="ch1t003 +.gif"/></table-wrap> </sec> </sec>

for example this line is moved to end of line when spoted table1.1 this is my code to move the lines

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $sgmfile= $ARGV[0]; my $key = ''; my $xline = ''; open (STDOUT, ">output.xml") or die $!; open (FILE, "<$sgmfile") or die "Can't open $sgmfile: $!\n"; my $line = ''; my %hash = (); my $hash = \%hash; my @tmpA = (); open (STDOUT, ">output.xml") or die $!; foreach $line (<FILE>) { chomp $line; if($line =~ m/<table-wrap id=(.*?) position=(.*?)><label>(.*?)<x> < +\/x><\/label><caption><p>(.*?)<\/caption><graphic xmlns:xlink=(.*?) x +link:href=(.*?)\/><\/table-wrap>/){ my @array = $line; ($hash,@tmpA) = recur(\@array); } else{print $line."\n";} } close FILE; open (XFILE, "<output.xml") or die "Can't open output.xml: $!\ +n"; foreach $key (sort (keys(%hash))) { print $key,"\n"; print $hash{$key},"\n"; foreach $xline(<XFILE>){ chomp $xline; if ($xline =~ m/$key/){ print $xline,$hash{$key},"\n"; delete $hash{$key}; } else{ print $xline,"\n";} } } close XFILE; sub recur($) { my $arrRef = $_[0]; my @procArr = @$arrRef; my $assign = ''; my @tmpArr = @procArr; shift(@tmpArr); my $arr = $procArr[0]; if ($arr =~ m/<table-wrap id=(.*?) position=(.*?)><label>(.*?)<x> +<\/x><\/label><caption><p>(.*?)<\/caption><graphic xmlns:xlink=(.*?) +xlink:href=(.*?)\/><\/table-wrap>/ig) { $assign = $3; my $tmpVal = ''; $tmpVal = "<table-wrap id=$1 position=$2><label>$3<x> <\/x><\/ +label><caption><p>$4<\/caption><graphic xmlns:xlink=$5 xlink:href=$6\ +/><\/table-wrap>"; $hash{$assign} = $tmpVal; foreach $line (<FILE>) { chomp $line;} } else{} return (\%hash, @tmpArr); }

this code is move the first line only please anyone help me to debug this code


In reply to file handling error 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.