We help IT Professionals succeed at work.

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

Dnguyen
Dnguyen asked
on
157 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

             
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Hope that helps.
(You can remove the braces from ${Line})

Commented:
can you attach your sample input file and also show how you want the output.
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
while( <IN> ){ print OUT "<a href="$_">$_</a>"; }
ozo
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
while( <IN> ){ print OUT qq(<a href="$_">$_</a>); }

Author

Commented:
Thank you, it worked! I'll release my script to to the world after it's done :)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.