[MarkLogic Dev General] xquery equivalent for perl code
sai shanker
lsaishanker at yahoo.com
Fri Jun 4 06:58:01 PDT 2010
Hello All,
To be more specific here is what i am trying to do is -
declare function local:a($str as xs:string) as xs:string
{
fn:replace($str, ' ','_')
};
let $str := 'John Doe, ref. nat. dr. med. vet. three ref. nat.'
let $newstr := fn:replace($str,'\s+',' ','i')
let $regexp := "(^| )(dr\.|ref\. nat\.|med. vet. three)( |$)"
return fn:replace($newstr,$regexp,local:a('$2'),'i')
i need to pass only the value of $2 wrt to the replace function (i.e ref. nat. ,
dr. , med. vet. three , ref. nat.) to the function which would replace the double space with a underscore but the literal '$2' gets passed to the function if i try local:a($2) it complains for a syntax error.
Is there any possible solution that i can use?
Thanks and Regards,
Sai.
--- On Thu, 6/3/10, sai shanker <lsaishanker at yahoo.com> wrote:
From: sai shanker <lsaishanker at yahoo.com>
Subject: [MarkLogic Dev General] xquery equivalent for perl code
To: "General Mark Logic Developer Discussion" <general at developer.marklogic.com>
Date: Thursday, June 3, 2010, 3:30 PM
Hello All,
I am trying to convert the following perl code into xquery. but am not getting the expected result. Can you please help me out?
Overview:- I am trying to append an underscore between multitoken titles.
Perl code:-
$str='John Smith, ref. nat. dr. med. vet. three ref. nat.';
print "$str\n";
$str =~ s/\s+/ /g;
print "$str\n";
sub a { my $title = shift; print "title=$title\n"; $title =~ s/ /_/g; return($title); }
$str =~ s/(^| )(dr\.|ref\. nat\.|med. vet. three)( |$)/$1 . a($2) . $3/eg;
$str =~ s/\s+/ /g;
print "$str\n";
output --- 'John Smith, ref._nat. dr. med._vet._three ref._nat.
Thanks and Regards,
Sai.
-----Inline Attachment Follows-----
_______________________________________________
General mailing list
General at developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20100604/21c7d586/attachment.html
More information about the General
mailing list