Ask a Question related to PERL Miscellaneous, Design and Development.
-
\Dandy\ Randy #1
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
-
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,... -
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 =... -
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... -
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... -
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... -
A. Sinan Unur #2
Re: URL detection follow-up
"\"Dandy\" Randy" <ducott@hotmail.com> wrote in
news:sMM7b.935815$3C2.21317890@news3.calgary.shaw. ca:
perldoc -q lib> 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.
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
-
Brian Wakem #3
Re: URL detection follow-up
""Dandy" Randy" <ducott@hotmail.com> wrote in message
news:sMM7b.935815$3C2.21317890@news3.calgary.shaw. ca...that> Hi,
>
> As per my previous posts, I am searching for a way to open a text filethis> 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 haveneeds.> module installed, and they are not prepared to install it just for my> 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
-
\Dandy\ Randy #4
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...with>
> ""Dandy" Randy" <ducott@hotmail.com> wrote in message
> news:sMM7b.935815$3C2.21317890@news3.calgary.shaw. ca...> that> > Hi,
> >
> > As per my previous posts, I am searching for a way to open a text file> > contains a few paragraphs of text, locate web URL's and replace themcannot> this> > 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> needs.> > module installed, and they are not prepared to install it just for my> > I also cannot change hosting companies.
> >
> > So ... is there ANY other way my goal can be accomplished giving Iany> > 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 haveeveryone!> > ideas, post back. Working code examples are very welcomed. Thanx>
>
> 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
-
Brian Wakem #5
Re: URL detection follow-up
""Dandy" Randy" <ducott@hotmail.com> wrote in message
news:VpN7b.927838$ro6.18582021@news2.calgary.shaw. ca...command> Awesome ... works great ... now ... can you formulate a replacementNice example of top posting.> 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
>
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
-
\Dandy\ Randy #6
Re: URL detection follow-up
"Brian Wakem" wrote:
a> To match email addresses perfectly every time is probably impossible, butBrian, thankx again, that one worked too. Here is what i'm now using that> simple and effective way of matching 99%+ would be:-
>
> foreach(@data) {
> s!([-\w.]+\@[-\w.]+)!<a href="mailto:$1">$1</a>!g;
> }
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
-
Brian Wakem #7
Re: URL detection follow-up
""Dandy" Randy" <ducott@hotmail.com> wrote in message
news:KEN7b.125548$la.2773409@news1.calgary.shaw.ca ...but> "Brian Wakem" wrote:
>> > To match email addresses perfectly every time is probably impossible,url,> 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 fullseemed> 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> 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



Reply With Quote

