CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
reading text file as data (orthing like that)

 



mwaf
Deleted

Jun 10, 2000, 9:35 AM

Post #1 of 3 (333 views)
reading text file as data (orthing like that) Can't Post

I have a text file....

------------------------------------------
$K114
$asdf
------------------------------------------

...and I want a perl file (starting)....

------------------------------------------
#!/usr/bin/perl

$K114 = "kubrick";
$asdf = "www.asdf.com";
------------------------------------------

...to open the text file (reading it as data) and print it so that the result would be:

------------------------------------------
kubrick www.asdf.com
------------------------------------------

Did anyone get the question? can anyone answer it?


jbs
Deleted

Jun 10, 2000, 9:10 PM

Post #2 of 3 (333 views)
Re: reading text file as data (orthing like that) [In reply to] Can't Post

You can do this!

open(FILE, "yourfile.txt") | | die "Error ";
while(<FILE> ){
if($_ eq "kubrick"){
$K114=$_;
chop($K114);#get rid of newline char

}
if($_ eq "www.asdf.com"){
$asdf=$_;
chop($asdf);
print "$K114 $asdf";
}
close(FILE);

Tell me if that is what you meant, but this is what I think you do.. This should work.


mwaf
Deleted

Jun 11, 2000, 5:01 AM

Post #3 of 3 (333 views)
Re: reading text file as data (orthing like that) [In reply to] Can't Post

I didn't get your script to work. Could you show exactly how both files should look like.

However, I've allready fixed my problem:

Perl file
------------------------------------------
#!/usr/bin/perl

$K114 = "kubrick";
$asdf = "www.asdf.com";

print "Content-type:text/html\n\n";
require "asdf";
------------------------------------------

Text file
------------------------------------------
print "$K114";print "$asdf";
------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives