Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am a newbie so please forgive my ignorance.... How can I create a link from an HTML document to a specific line in a text document?
  • Comment on link html to a specific line in a txt doc

Replies are listed 'Best First'.
Re: link html to a specific line in a txt doc
by graff (Chancellor) on Nov 21, 2002 at 02:15 UTC
    Maybe you would like to set up some sort of HTML Template mechanism, whereby you have a static, one-size-fits-all HTML wrapper that can be used to bracket any particular plain-text file; the text file would need just a couple very simple alterations, if the template went something like this:
    <HTML> <BODY> <PRE> # text file goes here </PRE> </BODY> </HTML>
    Now, the only things you have to worry about are:
    1. Convert any angle brackets within the text file to entity references, &lt; and &gt;, and
    2. Put the necessary anchor tags at the lines of interest.

    (and you could number the lines, if that's not done yet and seems helpful to the reader).

Re: link html to a specific line in a txt doc
by BrowserUk (Patriarch) on Nov 20, 2002 at 21:18 UTC

    I think that your question is likely to fall on deaf ears unless you can show that this is a Perl related question.


    Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
    Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
    Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
    Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

      I am parsing a series of text files for errors and displaying the results as an HTML document. I want to create links to the specific line of each document from which the error occurred. Is this possilbe to do through perl? Thanks

        If its possible to 'link' to a line of a text document from an HTML page, then it is possible to use perl to generate that link as part of an HTML page.

        The problem really centers around what you mean by the term 'link'.

        It is possible to to use an HTML anchor (<a>) to move to a specified point (note: not line) with the same HTML document or to a specified point within another HTML document using the <A href="#section">... or <a href="document.htm#section">... syntax, but that requires that the target be marked up using html and the target section be a named element within the target document. Note. This is pure HTML and nothing to do with perl. Is is, of course, possible to generate these links and their targets using perl.

        However, you said that the target documents are text files, and as such, there are no elements to form the basis of the targets. Unless it is your intention to markup the text documents with HTML, line by line, I don't see an easier way of doing this, using Perl or otherwise.


        Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
        Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
        Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
        Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.