Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Parsing Table

by prasadbabu (Prior)
on Aug 17, 2010 at 09:42 UTC ( #855447=note: print w/replies, xml ) Need Help??


in reply to Parsing Table

Hi tej,

As marto said it is always good to use parsers to have neat solution. Anyhow you have not given your exact output, so below code may satisfy your requirement.

$str = '<Tr><Tc>PA Group (N <26> 23)<Tc>COM Group (N <26> 24)<Tc> <Tr>Gender<Tc><Tc><Tc><124><sup>2<reset> test <26> 0.216, <mdit>df<med +> <26> 1, <mdit>P<med> <26> 0.642 <Tr><ems>Male (%)<Tc>14<ths>(60.9)<Tc>13<ths>(54.2)<Tc> <Tr><ems>Female (%)<Tc>9<ths>(39.1)<Tc>11<ths>(45.8)<Tc> <Tr>Ethnicity<Tc><Tc><Tc><124><sup>2<reset> test <26> 24.99, <mdit>df< +med> <26> 4, <mdit>P<med> <178> 0.001 <Tr><ems>African American (%)<Tc>5<ths>(21.7)<Tc>2<ths>(8.3)<Tc> <Tr><ems>European American (%)<Tc>5<ths>(21.7)<Tc>17<ths>(70.8)<Tc> <Tr><ems>Asian American (%)<Tc>0<Tc>4<ths>(16.7)<Tc> <Tr><ems>Hispanic American (%)<Tc>0<Tc>1<ths>(4.2)<Tc> <Tr><ems>Other (%)<Tc>9<ths>(39.1)<Tc>0<Tc> <Tr>Age, yr (SD)<Tc>46.05<ths>(6.13)<Tc>30.35<ths>(10.85)<Tc><mdit>t<m +ed> <26> 5.94, <mdit>P<med> <178> 0.001 <Tr>Education, yr (SD)<Tc>11.37<ths>(2.31)<Tc>15.85<ths>(1.75)<Tc><mdi +t>t<med> <26> 7.41, <mdit>P<med> <178> 0.001 <Tr>Pain Threshold, <28>C (SD)<Tc>48.75<ths>(2.44)<Tc>47.33<ths>(3.24) +<Tc>U* <26> 158.0, <mdit>P<med> <26> 0.012 <Tr;;4><ems>Males (SD) <26> 47.77 (3.35)&dagger; <Tr;;4><ems>Females (SD) <26> 48.26 (2.36)&dagger; <Tr;;4><ems>U&Dagger; <26> 244, <mdit>P<med> <26> 0.582<endtab>'; $str = qr{$str}; while ($str =~ m|((<Tr(?:\;)*(?:\d)*>)([^\n]*)<Tc>)|g){ push (@cells, $1) } print @cells;

Prasad

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://855447]
help
Chatterbox?
[stevieb]: did my pull request challenge today, Locale::gettext. Weird layout for a dist, and I have no idea how to use it, but it's always nice when you can force someone else's work be use strict; and use warnings; compliant :)
[stevieb]: ahem... s/no idea how to use it/didn't read enough as to what it's used for/
[stevieb]: interestingly enough, someone else got my Devel::Examine:: Subs distribution for their PRC, and I applaud the change. This dist is extremely complicated and mostly obfu, but the person doing it understood PPI enough to change...
[stevieb]: ...something I had overlooked in the extreme depths of the core functionality. After merging, then a couple of extra tweaks, I still have 100% test coverage. Yay for people who write tests!

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2017-01-24 01:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (199 votes). Check out past polls.