ffdb read trouble

  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

Hey its me agen im havin problems with my flat file database it writes to it fine from the form but im having trouble getting it to read the file here is the read source im using:
Code: [ Select ]
#!/usr/bin/perl -w

use strict;

open (INPUT, "file.txt") or die "Can't open data file: $!";

while (<INPUT>) {
    chomp;         
    my @fields = split(/\|/, $_);
    print "$fields[1], $fields[0]: $fields[2]\n";
}

close INPUT;
  1. #!/usr/bin/perl -w
  2. use strict;
  3. open (INPUT, "file.txt") or die "Can't open data file: $!";
  4. while (<INPUT>) {
  5.     chomp;         
  6.     my @fields = split(/\|/, $_);
  7.     print "$fields[1], $fields[0]: $fields[2]\n";
  8. }
  9. close INPUT;

well it didnt work as a separate file with the shebang etc so i integrated into the one that handles the form so it prints it out after u press submit all the words in the ffdb are delimited by pipe. Ive tried taking the print command out and putting in the field scalars into the html and it doesnt show the field scalars so i dont know what to do to resolve it
d7
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9086
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Are you trying to get that to print out to your webpage? or just in a console on your machine?

If you are wanting to get it to print out to web page do not forget that before you start printing out any text to a webpage, that the statement:

print "Content-Type: text/html\n\n";

has occurred. As long as that statement has been executed somewhere before you print out to a webpage then this would not be the problem. However in your script if you have not executed this statement yet and you try printing out to a web page, you will not see anything. Let me know if that solves your problem.
  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

well.. on the integrated one it has that line in it but not the external one i changed it to
Code: [ Select ]
#!/usr/bin/perl -w

use strict;

open (INPUT, "db1.dat") or die "Can't open data file: $!";

while (<INPUT>) {
    chomp;         
    my @fields = split(/\|/, $_);
$header = "Content-Type: text/html\n\n";
$html = "$fields[1], $fields[0]: $fields[2]\n";
print "$html$header"
}

close INPUT;
exit;
  1. #!/usr/bin/perl -w
  2. use strict;
  3. open (INPUT, "db1.dat") or die "Can't open data file: $!";
  4. while (<INPUT>) {
  5.     chomp;         
  6.     my @fields = split(/\|/, $_);
  7. $header = "Content-Type: text/html\n\n";
  8. $html = "$fields[1], $fields[0]: $fields[2]\n";
  9. print "$html$header"
  10. }
  11. close INPUT;
  12. exit;

and it still didnt work with the error log saying it has "premature end of script headers"
  • dreamer7
  • Student
  • Student
  • dreamer7
  • Posts: 95
  • Loc: UK

Post 3+ Months Ago

and.. before u say i changed the file name of the flat file database to db1.dat
:D
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9086
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

dreamer7 wrote:
well.. on the integrated one it has that line in it but not the external one i changed it to
Code: [ Select ]
#!/usr/bin/perl -w

use strict;

open (INPUT, "db1.dat") or die "Can't open data file: $!";

while (<INPUT>) {
    chomp;         
    my @fields = split(/\|/, $_);
$header = "Content-Type: text/html\n\n";
$html = "$fields[1], $fields[0]: $fields[2]\n";
print "$html$header"
}

close INPUT;
exit;
  1. #!/usr/bin/perl -w
  2. use strict;
  3. open (INPUT, "db1.dat") or die "Can't open data file: $!";
  4. while (<INPUT>) {
  5.     chomp;         
  6.     my @fields = split(/\|/, $_);
  7. $header = "Content-Type: text/html\n\n";
  8. $html = "$fields[1], $fields[0]: $fields[2]\n";
  9. print "$html$header"
  10. }
  11. close INPUT;
  12. exit;

and it still didnt work with the error log saying it has "premature end of script headers"


Well that is wrong (the above). You want the header to go before the html, plus you do not want to loop that header over and over. Change it to:

Code: [ Select ]
#!/usr/bin/perl -w

use strict;


$header = "Content-Type: text/html\n\n";
print "$header";

open (INPUT, "db1.dat") or die "Can't open data file: $!";
while (<INPUT>) {
    chomp;         
    my @fields = split(/\|/, $_);
$html = "$fields[1], $fields[0]: $fields[2]\n";
print "$html"
}

close INPUT;
exit;
  1. #!/usr/bin/perl -w
  2. use strict;
  3. $header = "Content-Type: text/html\n\n";
  4. print "$header";
  5. open (INPUT, "db1.dat") or die "Can't open data file: $!";
  6. while (<INPUT>) {
  7.     chomp;         
  8.     my @fields = split(/\|/, $_);
  9. $html = "$fields[1], $fields[0]: $fields[2]\n";
  10. print "$html"
  11. }
  12. close INPUT;
  13. exit;

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 104 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.