Current location: Hot Scripts Forums » Programming Languages » Perl » Adding each line from 2 text box


Adding each line from 2 text box

Reply
  #1 (permalink)  
Old 05-15-06, 08:07 AM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Adding each line from 2 text box

Hi to all!

I have two .dat files. one contain URLs and another file contents Description of each url.

Using a CGI script, it read these files and store their values into 2 textarea box of a HTML Form, now I would like to take each line on both boxes and convert each one into link with Description.

for convert URLs to active link i have done the following thinks:

$add1 = $query->param('add');
$add =~ s/\r?\n/<br>/g;

($adv = $add1) =~ s/(\w+:\/\/)([.a-zA-Z0-9\-~\/]*)/<a href=\"$1$2\" target=\"_blank\">$1$2<\/a>/g;

but i would like to take the rite decsription of this URL from the description textarea box and replace that value in place of this $1$2.

So that at last when this CGI script create a html with active link, those link should take each url and correspondence description from those textarea box.

if anyone have solve this type of problem please guide me.

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 05-15-06, 11:31 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
You should get the contents of the textare boxes into arrays, then loop through each array to do what you want. Why are the contents of both files being put in textarea boxes anyway?
Reply With Quote
  #3 (permalink)  
Old 05-15-06, 11:42 PM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Millenium,

I have putted putted matter into textarea box, for further instant modification. that's all.

I also understand that i have to take two array and put those boxes value each of them. but i can't able to do coding for both array at a time. i have tried the following one, but it not giving me desired result. please let me know the proper one.

Code:
my $lines = "file.dat";
open(DATA, $lines);
my @lines = <DATA>;
close(DATA);

foreach my $line (@lines) {

($adv2 = $url) =~ s/(\w+:\/\/)([.a-zA-Z0-9\-~\/]*)/<a href=\"$1$2\" target=\"_blank\">$line<\/a><br>/g;

}
print DATAF ($adv2);
Kindly suggest me how do i execute two array same time?
Reply With Quote
  #4 (permalink)  
Old 05-16-06, 02:03 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
please post some sample lines from the .dat files. Do both files have the same number of lines and does each line correspond with each line in each file, like line one in file1 corresponds with line one in file2?
Reply With Quote
  #5 (permalink)  
Old 05-16-06, 11:01 PM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, both dat files have same line.

Line 1 on B file is corresponding with line 1 of B file.

some example are:

File A:
page1.html
page2.html
page3.html
page4.html
page5.html

File B:
Title 1
Title 2
Title 3
Title 4
Title 5

the program will replace the page1.html with following pattern and add link description, taking from the file for this perticular html page as follows:

<a href="page1.html" target=blank>Title 1</a><br><br>

and store each line in a another .dat file. and using copy command make a html page on specific directory.

Thanks once more for spending your valuable time to help me.

Last edited by sujata_ghosh; 05-16-06 at 11:04 PM.
Reply With Quote
  #6 (permalink)  
Old 05-17-06, 12:01 AM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
This would be easier if you used one file:

Code:
file A:

page1.html Title 1
page2.html Title 2
page3.html Title 3
etc 
etc
etc
but I'll work with what you have, here is one possible way:

Code:
open(LINKS,'<file_a.dat') or die "$!";
open(DESC,'<file_b.dat') or die "$!";
while (my $links = <LINKS>) {
   chomp($links);
   chomp(my $desc = <DESC>);
	print qq~<a href="$links" target=blank>$desc</a><br><br>\n~;
}
close(LINKS);
close(DESC);
Reply With Quote
  #7 (permalink)  
Old 05-17-06, 07:05 AM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks a lot millenium!

yes i have tried the first one which you have suggest, it is working. as follows:

Code:
my $lines = "/home/web/k/k****ij.com/htdocs/datfile/test.dat";
open(FILE, $lines);
my @lines = <FILE>;
close(FILE);

foreach my $line (@lines) {

($url, $dec) = split (/\t|\n/, $line);

($adv2 = $url) =~ s/(\w+:\/\/)([.a-zA-Z0-9\-~\/]*)/<a href=\"$1$2\" target=\"_blank\">$dec<\/a><br>/g;
print qq~$adv2\n~;

the second one for which I was asking for is also working now.

thanks a lot for your time and effort.
Reply With Quote
  #8 (permalink)  
Old 05-17-06, 02:29 PM
Millennium's Avatar
Millennium Millennium is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
Why are you using the regxp to create the html tag? Is there other data in the .dat file besides the link and the desc? Can you post some real lines of data from the .dat file?
Reply With Quote
  #9 (permalink)  
Old 05-17-06, 10:36 PM
sujata_ghosh sujata_ghosh is offline
Wannabe Coder
 
Join Date: May 2006
Posts: 181
Thanks: 0
Thanked 0 Times in 0 Posts
I am using the regxp because firstly the links were with other data on File A. but now I have got a File with only links and one with Description. But the thing is I have forgot to remove the Regxp part. Now no need of it. Opps! that's my mistake.

Thanks Millennium for your effort & concern.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 03:27 PM
Redirection back to a page from form submit DAL Perl 11 03-21-05 02:45 PM
I most definately suggest DevelopingCentral.com For Any Website Design/Development! Salty777 General Advertisements 2 10-01-04 04:27 AM
asp-iis-Server error nsuresh_rasr ASP.NET 3 02-08-04 12:47 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


All times are GMT -5. The time now is 04:09 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.