By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,681 Members | 1,806 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,681 IT Pros & Developers. It's quick & easy.

How to change a url to hyperlink?

P: 3
Hi,

Thanks for reading this. I have searched all over the web but found no solution. How would one change a url to a hyperlink and email the hyperlink...I parsed through an html file to get this

Expand|Select|Wrap|Line Numbers
  1. </table><br><div><a class="red_link" href="http://dabcd123456:80/results/report.jsp?a=HGUYU&amp;b=HGUYU&amp;c=%2Fc%2B%2Btest%2F&amp;id=%3Ademd140149%3A1193283688721.html%2BDefault%2Bsmith%3A">TCM report &gt;&gt;&gt;</a></div><br><table width="95%" border="1" bordercolor="#999999" cellpadding="0" cellspacing="0">
  2.  
and I parse and got the url out:
"http://dabcd123456:80/results/report.jsp?a=HGUYU&amp;b=HGUYU&amp;c=%2Fc%2B%2Btes t%2F&amp;id=%3Ademd140149%3A1193283688721.html%2BD efault%2Bsmith%3A">

How can I change the url into a hyperlink and send that link in an email to someone?

Thanks,
Monkey
Oct 25 '07 #1
Share this Question
Share on Google+
6 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
What have you tried thus far? Can you please share your code with us?

Regards,

Jeff
Oct 25 '07 #2

P: 3
Hi,

I tried a bunch of stuff, but they don't work, so I deleted them already..this is the last thing I tried ##my $content = get $url; that doesn't work either. I also tried the string replacement, but that's too cumbersome and if the url changes it would be no good! $text =~ s[($RE{URI}{HTTP})] doesn't work
This is what I have so far that works in extracting the URL

Expand|Select|Wrap|Line Numbers
  1.  my($File) = @_;
  2.   open(STDIN, $File) || die("Could not open file!");
  3.   while(<STDIN>){
  4.      my($data)=$_;
  5.      ##print "$data \n";
  6.      if ($data =~ m/(http.*).+report/i ){
  7.         ##print "$1 \n"
  8.      }   
  9.  }
  10. close(STDIN);
  11.  
Please help!

Thanks,
Monkey
Oct 25 '07 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
Monkey,

In your original post and in the last post, I had to place the necessary code tags in your post. Please be sure, per the document in the link, to add them to all future code posting.

Regards,

Moderator
Oct 25 '07 #4

eWish
Expert 100+
P: 971
Would you please post some sample data from the file you are using? If you are getting a match into $1 and it contains only the url then you can do something like this.
Expand|Select|Wrap|Line Numbers
  1. my($File) = @_;
  2.   open(STDIN, $File) || die("Could not open file!");
  3.        while(my $data = <STDIN>){
  4.             if ($data =~ m/(http.*).+report/i ){
  5.                 my $link  = qq{<a href="$1">Click Me</a>};
  6.                   &send_email($link);  #Send $link as an arugement to a sub that will then include the $link in the body of the message.
  7.              }   
  8.          }
  9. close(STDIN);
  10.  
  11. sub send_email {
  12.  
  13.     my ($email_link) = @_;
  14.  
  15.     my $message_type = 'text/html';
  16.     my $from_email = 'From@someemail.com';
  17.     my $to_email = 'To@someemail.com';
  18.     my $subject = 'Requested Link';    
  19.     my $message = qq{Hello here is your link $email_link};
  20.  
  21.     #You can use any email module you wish.  Example given with Mime::Lite;
  22.     use Mime::Lite;
  23.  
  24.     my $msg = MIME::Lite->new(
  25.         From    => $from_email,
  26.         To        => $to_email,                
  27.         Subject => $subject,
  28.         Type    => $message_type,
  29.         Data    => $message
  30.     );
  31.  
  32.     $msg->send() || die "Couldn't send message:";
  33. }
Oct 26 '07 #5

P: 3
Hi eWish,

Thank you for your response, this is what I need. Thanks so much. You save me hours =)

Monkey
Oct 29 '07 #6

eWish
Expert 100+
P: 971
Glad to hear it helped. :)
Oct 30 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.