Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Text Processing - Constructing Hyperlinks

by gav^ (Curate)
on May 01, 2002 at 23:26 UTC ( [id://163422]=note: print w/replies, xml ) Need Help??


in reply to Text Processing - Constructing Hyperlinks

I think this might be close, I'm not exactly sure what output you want for those test cases. You might have to tweak the return statement slightly in fix_xref. Usual warnings about parsing apply, is there optional white space, can the link text contain a '>', etc.
sub fix_xref { my ($parts, $text, $ref, $action, $link_text) = @_; $parts =~ s@(\d+(?:\.\d+)?(?:\([\w\d]+\))*)@<JL:ref$ref,"$action $ +1">s. $ref</JL>@g; return qq@$parts $text <JL:ref$ref,"$action">$link_text</JL>@; } while (<DATA>) { s@s\. (.+?) (of(?: the)) <JL:ref(\d+),"([^"]+)">([^<]+)</JL>@fix_x +ref($1,$2,$3,$4,$5)@eg; print; print "\n"; } __DATA__ s. 3 and 4 of the <JL:ref2,"Interpretation Act">Interpretation Act</JL +> s. 3 or 5 of the <JL:ref2,"Interpretation Act">Interpretation Act</JL> + s. 3, 4, 5, 6, 7 or 8 of the <JL:ref2,"Interpretation Act">Interpretat +ion Act</JL>

gav^

Replies are listed 'Best First'.
Re: Re: Text Processing - Constructing Hyperlinks
by meraxes (Friar) on May 02, 2002 at 13:04 UTC

    That doesn't do exactly what I want it to, but I see now how to work it! Many thanks!

    The "JL:ref2" part of the link is static. The "ref2" is a link style so it doesn't actually need to be changed so I wasn't sure what it was you were doing with it. I also didn't need the "s." in front of each number. Just the first. You have given me the tools I need to figure it out though!

    UPDATE

    Okay, here's what I developed from it:

    sub link_numbers ($$) { my $data = $_[0]; my $link = $_[1]; $data =~ s/([s]?s\. )?(\d+(?:\.\d+)?(?:\([^\)]+\))*)/<JL:ref2,\"$li +nk $2\">$1$2<\/JL>/g; return $data; } while ($line = <DATA>) { $line =~ s/ ((?:(?:[s]?s\. )?\d+(?:\.\d+)?(?:\([^\)]+\))*(?:, | an +d | or )?)+)((?: of| the|,)+ )(<JL:ref2,\"([^\">]+)\">)/" " . link_nu +mbers($1,$4) . "$2$3"/ge; print $line; print "\n"; } __DATA__ This can be found in ss. 3 and 4 of the <JL:ref2,"Interpretation Act"> +Interpretation Act</JL>. As discussed in s. 3 or 5 of the <JL:ref2,"Interpretation Act">Interpr +etation Act</JL>. Filling up space in ss. 3, 4, 5, 6, 7 or 8 of the <JL:ref2,"Interpreta +tion Act">Interpretation Act</JL> .

    Again, many thanks. You saved my bacon.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-03-28 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found