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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.