Solved

Read a file and output to a new file... plz help

Posted on 2000-03-15
6
134 Views
Last Modified: 2010-03-05
here's a cut/paste of my code:

$INFILE="list.txt";
$OUTFILE="out.txt";

open(IN,"$INFILE");
@lines=<IN>;
close(IN);

open(OUT,">$OUTFILE");          
foreach(@lines){
print OUT "@lines";
}
close(OUT);


*The problem is I want it to print out each line with extra characters but it is messing up... I can't figure out why. ex:
print OUT "a @lines b";
would give someting like this in the text file:
ab blah <which is a line in the txt file.


What I'm trying to do is open a input txt file and read that file then write each line to a new file that will add extra words that I place in such as <a href=\"@lines"\>@lines</a> to make each line a URL but it is messing up.

If you can change my code around to make this work or re-write it entirely, please do. I need an answer ASAP! thank you!

Zoned

             
0
Comment
Question by:Dnguyen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Accepted Solution

by:
PC_User321 earned 25 total points
ID: 2622635
open(IN, $INFILE);
@lines=<IN>;
close(IN);

open(OUT,">$OUTFILE");          
foreach $Line (@lines){
   chomp $Line;
   print OUT "<a href=${Line}></a>\n";
}
close(OUT);
0
 
LVL 5

Expert Comment

by:PC_User321
ID: 2622650
Hope that helps.
(You can remove the braces from ${Line})
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2623966
can you attach your sample input file and also show how you want the output.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 2624336
while( <IN> ){ print OUT "<a href="$_">$_</a>"; }
0
 
LVL 84

Expert Comment

by:ozo
ID: 2624350
while( <IN> ){ print OUT qq(<a href="$_">$_</a>); }
0
 

Author Comment

by:Dnguyen
ID: 2632635
Thank you, it worked! I'll release my script to to the world after it's done :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question