Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Capture a string

by Punitha (Priest)
on Feb 28, 2008 at 11:53 UTC ( #670893=note: print w/replies, xml ) Need Help??


in reply to Capture a string

Hi,

I have tried to produce the exact output of yours with the same input, i got these codes,

use strict; while(<DATA>){ chomp; $_=~s/(<citref idrefs=\")([^"]*)(\">)((?:(?!<\/citref>).)*)(<\/cit +ref>)/$1.idgen($2,$4).$3.citeref($4).$5/sgie; print "$_\n"; } sub idgen{ my ($id,$idcon) = @_; if($idcon =~/,/){ $idcon=~s/([^,]+)(?=,|$)/$id$1/gi; $idcon=~s/,/ /gi; } else{ $idcon=$id.$idcon; } return($idcon); } sub citeref{ my ($con) = @_; if($con =~/,/){ my (@con) = split/,/,$con; map{s/[a-z]+/<it>$&<\/it>/i} @con; $con =join(',',@con); } else{ $con =~s/[a-z]+/<it>$&<\/it>/gi; } return($con); }

__DATA__ <citref idrefs="cit">5c,5d</citref> <citref idrefs="cit">5d</citref>

But please explain us furthermore to provide you the better solution like,

    1. The content of the 'citref' tag (i.e) it will always contain the comma or not
    2. The idrefs generated in the output should be preceded with the idref content of input or it will always be 'cit'

Punitha

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://670893]
help
Chatterbox?
[choroba]: That still doesn't make it offensive
[LanX]: of course not
[LanX]: it's pretty ironic if you know the character
choroba likes the movie
[choroba]: Lady_Aleena Do you really need to say "WorldBuilder" after having said "WorldBuilding"?
[LanX]: have to watch it again :)

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-05-24 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?