Closed Thread Icon

Topic awaiting preservation: Open File, Read File,Close File. ISE.. DAM (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12532" title="Pages that link to Topic awaiting preservation: Open File, Read File,Close File. ISE.. DAM (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Open File, Read File,Close File. ISE.. DAM <span class="small">(Page 1 of 1)</span>\

 
Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 11-27-2002 21:46

Greetz, More Problems with Trigs quest to Learn Perl
I wrote this

quote:
#!/usr/bin/perl -w

$html = "content-type:text/html\n\n";
if(open(BLOG,"/home/thebronze/www/UPD/blog.txt")) {
while(<BLOG> ){
print $_;
}
close BLOG;
} else {
dienice("Can't open blog.txt for Reading");
}


print "$_";
sub dienice {
print "$html";
print "<h2>Error</h2>\n";
exit;



Whats wrong with it?
I really cant see the problem
Thanks
Trigger

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-27-2002 22:06

Hokay couple of things

First I dunno if it's a cut and paste error but you're missing the last curly brace
Second this line:

print "$_";

should be in the dienice subroutine

Third if something fails (ie the open) the error gets stuck in the magic variable $!
so if you change this line
dieice("Can't open blog.txt for Reading");

to

dieice("Can't open blog.txt for Reading $!");

Are you testing this by ftp ing to a server and viewing it in a browser? This can really suck otherwise I'd do my testing from a shell for perl. Many more options there.





.:[ Never resist a perfect moment ]:.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-27-2002 22:10

oh this works fine on mine.

code:
#!/usr/bin/perl -w

$html = "content-type:text/html\n\n";
if(open(BLOG,"/home/mikey/perl/text.txt")) {
while(<BLOG> ){
print $_;
}
close BLOG;
} else {
dienice("Can't open blog.txt for Reading $!");
}


sub dienice {
print "$html \n";
print $_;
print "<h2>Error</h2>\n";
exit;
}





.:[ Never resist a perfect moment ]:.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-27-2002 22:16

and hell I'm bored so here's another way to write it (and much more perl like) you may want to look at the strict pragma in a bit. Virtually noone uses perl without it these days

code:
#!/usr/bin/perl -w

$html = "content-type:text/html\n\n";
$file = "/home/mikey/perl/text.txt";
open(BLOG, $file) or dienice($!);
while(<BLOG> ){
print $_;
}
close BLOG;
sub dienice {
print "$html \n";
print "<h2>Error</h2>\n";
print "Could not open $file for reading @_";
exit;
}





.:[ Never resist a perfect moment ]:.

« BackwardsOnwards »

Show Forum Drop Down Menu