Solved

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

Posted on 2000-03-15
6
130 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
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PERL export multiple query results to a JSON file 1 165
stftime format 4 56
problem with using the glob function 1 69
Bash one liner, start and end time calculation 13 111
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

773 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