Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Regex problem while parsing tagged, hierarchical data

by Mago (Parson)
on Sep 19, 2006 at 11:25 UTC ( #573688=note: print w/ replies, xml ) Need Help??


in reply to Re: Regex problem while parsing tagged, hierarchical data
in thread Regex problem while parsing tagged, hierarchical data

perl -pi -e 'if(/<level1(\sid=\".*\")>/){$a=$1};if(/<level2>/){$_=~s/( +<level2)>/$1$a>/g}' input or perl -pi -e '$a=m/(<level([12]))(\sid=\".*\")*>/;if($a){$2==1?$b=$3:$_ +=~s/($1)/$1$b/g;}' input or perl -pi -e '$a=m/(<level(1|2))(\sid=\".*\")*>/;$a?$2==1?$b=$3:$_=~s/( +$1)/$1$b/g:next;' input or perl -pi -e '$a=m;(<level(1|2))(\sid=\".*\")*>;;$a?$2==1?$b=$3:$_=~s;( +$1);$1$b;g:1;' input
or golf by monsieur_champs
perl -pi -e 'm;(<level(1|2))(\sid=\".*\")*>;;$&?$2==1?$b=$3:$_=~s;($1) +;$1$b;g:1;' input
sorry =) -1 char
perl -pi -e 'm;(<level(1|2))(\sid=\".*\")*>;;$&?$2==1?$b=$3:$_=~s;($1) +;$1$b;g:1' input
insane !!! 33 chars
perl -pi -e '/l1(\sid=.*)>/?$a=$1:s;l2>;l2$a>;' input

=)


Mago
mago@rio.pm.org



Comment on Re^2: Regex problem while parsing tagged, hierarchical data
Select or Download Code
Re^3: Regex problem while parsing tagged, hierarchical data
by smokemachine (Hermit) on Sep 19, 2006 at 12:53 UTC
    perl -pi -e '/(<level(1|2))(\sid=\".*\")*>/;$&?$2==1?$b=$3:$_=~s;($1);$1$b;g:1;' input
      Ups !! -1 char
      perl -pi -e '/(<level(1|2))(\sid=\".*\")*>/;$&?$2==1?$b=$3:$_=~s;($1); +$1$b;g:1' input


      Mago
      mago@rio.pm.org


        perl -pi -e '/(<level(1|2))( id=\".*\")*>/;$&?$2==1?$b=$3:$_=~s;($1);$1$b;g:1' input

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://573688]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-10-02 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls