URL detection follow-up

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default URL detection follow-up

    Hi,

    As per my previous posts, I am searching for a way to open a text file that
    contains a few paragraphs of text, locate web URL's and replace them with
    the needed html tags such as <a href & </a> etc. Most of the responses
    suggested using a perl module ... URI::Find and similair methods.
    Unfortunately, the hosting company I run my scripts from does not have this
    module installed, and they are not prepared to install it just for my needs.
    I also cannot change hosting companies.

    So ... is there ANY other way my goal can be accomplished giving I cannot
    use URI::Find? Here is an example of theoretical code:

    #!/usr/bin/perl

    # get text file data
    open (TEXT, "<data/data.txt") or die "Can't open file: $!";
    @data=<TEXT>;
    close(TEXT);

    # find web URL's and replace occurances with needed HTML tags
    scan @list > replace;

    # write the changed data back to the text file
    open (TEXT, ">data/data.txt") or die "Can't open file: $!";
    print DATA @text;
    close(TEXT);

    Please, it is very important to me to find this solution, if you have any
    ideas, post back. Working code examples are very welcomed. Thanx everyone!

    Randy


    \Dandy\ Randy Guest

  2. Similar Questions and Discussions

    1. terrain follow
      hi there i?m having some problems with a scene. i can?t have my character to move along a terrain. it detects the terrain, if the terrain goes up,...
    2. Please help with follow mouse!
      Hello I have a menu with a movie clip that slides following the mouse, up and down The code looks as follows onClipEvent (load) _y = 0 speed =...
    3. ASPHTTP Doesn't Follow Redirects
      How can I get ASPHTTP to follow Redirects? I set the followRedirects property to TRUE, but whenever there is a redirection, the results string...
    4. FOLLOW SPRITE
      Okay, all I want to do is have a sprite follow another sprite. Obviously this can be done with Behaviors, but the game/interactive learning is going...
    5. Copying to disk-follow-up
      John Mc. Thanks for your reply. I am new at this and do not understand your instructions. What I want to do is copy all of my emails (none of...
  3. #2

    Default Re: URL detection follow-up

    "\"Dandy\" Randy" <ducott@hotmail.com> wrote in
    news:sMM7b.935815$3C2.21317890@news3.calgary.shaw. ca:
    > methods. Unfortunately, the hosting company I run my scripts from does
    > not have this module installed, and they are not prepared to install
    > it just for my needs. I also cannot change hosting companies.
    perldoc -q lib
    Found in C:\Perl\lib\pod\perlfaq8.pod

    How do I keep my own module/library directory?

    When you build modules, use the PREFIX option when generating
    Makefiles:

    perl Makefile.PL PREFIX=/u/mydir/perl

    then either set the PERL5LIB environment variable before you run
    scripts that use the modules/libraries (see perlrun) or say

    use lib '/u/mydir/perl';

    This is almost the same as

    BEGIN {
    unshift(@INC, '/u/mydir/perl');
    }

    except that the lib module checks for machine-dependent
    subdirectories. See Perl's lib for more information.


    --
    A. Sinan Unur
    [email]asu1@c-o-r-n-e-l-l.edu[/email]
    Remove dashes for address
    Spam bait: mailto:uce@ftc.gov
    A. Sinan Unur Guest

  4. #3

    Default Re: URL detection follow-up


    ""Dandy" Randy" <ducott@hotmail.com> wrote in message
    news:sMM7b.935815$3C2.21317890@news3.calgary.shaw. ca...
    > Hi,
    >
    > As per my previous posts, I am searching for a way to open a text file
    that
    > contains a few paragraphs of text, locate web URL's and replace them with
    > the needed html tags such as <a href & </a> etc. Most of the responses
    > suggested using a perl module ... URI::Find and similair methods.
    > Unfortunately, the hosting company I run my scripts from does not have
    this
    > module installed, and they are not prepared to install it just for my
    needs.
    > I also cannot change hosting companies.
    >
    > So ... is there ANY other way my goal can be accomplished giving I cannot
    > use URI::Find? Here is an example of theoretical code:
    >
    > #!/usr/bin/perl
    >
    > # get text file data
    > open (TEXT, "<data/data.txt") or die "Can't open file: $!";
    > @data=<TEXT>;
    > close(TEXT);
    >
    > # find web URL's and replace occurances with needed HTML tags
    > scan @list > replace;
    >
    > # write the changed data back to the text file
    > open (TEXT, ">data/data.txt") or die "Can't open file: $!";
    > print DATA @text;
    > close(TEXT);
    >
    > Please, it is very important to me to find this solution, if you have any
    > ideas, post back. Working code examples are very welcomed. Thanx everyone!

    If they are all like [url]http://www.domain.com/dir/file.html[/url] then you could do
    something like -


    foreach(@data) {
    s!(http://.*?)(?:\s|$)!<a href="$1">$1</a>!gi;
    }

    Not perfect, but it'll get you started.

    --
    Brian Wakem


    Brian Wakem Guest

  5. #4

    Default Re: URL detection follow-up

    Awesome ... works great ... now ... can you formulate a replacement command
    that will take an email address and add the <a href="mailto: commands so
    that email addresses will also become linked? You've been agreat help!

    Randy

    "Brian Wakem" <no@email.com> wrote in message
    news:bjo6ce$lfb7n$1@ID-112158.news.uni-berlin.de...
    >
    > ""Dandy" Randy" <ducott@hotmail.com> wrote in message
    > news:sMM7b.935815$3C2.21317890@news3.calgary.shaw. ca...
    > > Hi,
    > >
    > > As per my previous posts, I am searching for a way to open a text file
    > that
    > > contains a few paragraphs of text, locate web URL's and replace them
    with
    > > the needed html tags such as <a href & </a> etc. Most of the responses
    > > suggested using a perl module ... URI::Find and similair methods.
    > > Unfortunately, the hosting company I run my scripts from does not have
    > this
    > > module installed, and they are not prepared to install it just for my
    > needs.
    > > I also cannot change hosting companies.
    > >
    > > So ... is there ANY other way my goal can be accomplished giving I
    cannot
    > > use URI::Find? Here is an example of theoretical code:
    > >
    > > #!/usr/bin/perl
    > >
    > > # get text file data
    > > open (TEXT, "<data/data.txt") or die "Can't open file: $!";
    > > @data=<TEXT>;
    > > close(TEXT);
    > >
    > > # find web URL's and replace occurances with needed HTML tags
    > > scan @list > replace;
    > >
    > > # write the changed data back to the text file
    > > open (TEXT, ">data/data.txt") or die "Can't open file: $!";
    > > print DATA @text;
    > > close(TEXT);
    > >
    > > Please, it is very important to me to find this solution, if you have
    any
    > > ideas, post back. Working code examples are very welcomed. Thanx
    everyone!
    >
    >
    > If they are all like [url]http://www.domain.com/dir/file.html[/url] then you could do
    > something like -
    >
    >
    > foreach(@data) {
    > s!(http://.*?)(?:\s|$)!<a href="$1">$1</a>!gi;
    > }
    >
    > Not perfect, but it'll get you started.
    >
    > --
    > Brian Wakem
    >
    >

    \Dandy\ Randy Guest

  6. #5

    Default Re: URL detection follow-up


    ""Dandy" Randy" <ducott@hotmail.com> wrote in message
    news:VpN7b.927838$ro6.18582021@news2.calgary.shaw. ca...
    > Awesome ... works great ... now ... can you formulate a replacement
    command
    > that will take an email address and add the <a href="mailto: commands so
    > that email addresses will also become linked? You've been agreat help!
    >
    > Randy
    >
    Nice example of top posting.

    To match email addresses perfectly every time is probably impossible, but a
    simple and effective way of matching 99%+ would be:-

    foreach(@data) {
    s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a>!g;
    }

    --
    Brian Wakem


    Brian Wakem Guest

  7. #6

    Default Re: URL detection follow-up

    "Brian Wakem" wrote:
    > To match email addresses perfectly every time is probably impossible, but
    a
    > simple and effective way of matching 99%+ would be:-
    >
    > foreach(@data) {
    > s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a>!g;
    > }
    Brian, thankx again, that one worked too. Here is what i'm now using that
    seems to work correctly:

    $contents=~ s/http:\/\///g;
    $contents=~ s!(www.*?)(?:\s|$)!<a href="http://$1">$1</a> !gi;
    $contents=~ s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a> !g;

    The first code eliminates the http:// in case the text contained a full url,
    then adjusted your code to start looking for www. You also may notice a
    deliberate space after the </a> tags ... this was needed as your code seemed
    to kill the trailing space. Owe you one.

    Randy

    P.S. Sorry about the last top post.


    \Dandy\ Randy Guest

  8. #7

    Default Re: URL detection follow-up


    ""Dandy" Randy" <ducott@hotmail.com> wrote in message
    news:KEN7b.125548$la.2773409@news1.calgary.shaw.ca ...
    > "Brian Wakem" wrote:
    >
    > > To match email addresses perfectly every time is probably impossible,
    but
    > a
    > > simple and effective way of matching 99%+ would be:-
    > >
    > > foreach(@data) {
    > > s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a>!g;
    > > }
    >
    > Brian, thankx again, that one worked too. Here is what i'm now using that
    > seems to work correctly:
    >
    > $contents=~ s/http:\/\///g;
    > $contents=~ s!(www.*?)(?:\s|$)!<a href="http://$1">$1</a> !gi;
    > $contents=~ s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a> !g;
    >
    > The first code eliminates the http:// in case the text contained a full
    url,
    > then adjusted your code to start looking for www. You also may notice a
    > deliberate space after the </a> tags ... this was needed as your code
    seemed
    > to kill the trailing space. Owe you one.

    Yes it would have swallowed the space.

    s!(http://.*?)(\s|$)!<a href="$1">$1</a>$2!gi;

    Instead should sort that out.

    I'm glad they worked for you, but it's important to understand why, in case
    you need to alter something. It's also important to understand why those
    regexs are not perfect and will not work for every url or email, and from
    time-to-time, could match things that aren't urls or email addresses.

    --
    Brian Wakem


    Brian Wakem Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139