Hey there.
I'm trying to pull the text from a file in my current directory called news.txt. With that text, i want' to populate a textarea so it is editable. But i can't seem to get all the lines from the file in there.
Any tips?
Heres the code.
#!/usr/local/bin/perl -w
use CGI qw
standard);
use CGI::Carp qw(fatalsToBrowser warningsToBrowser carpout);
warningsToBrowser(1); # activate warnings
open NEWS, "<news.txt"
or die "Coulden't open news.txt: $!.";
my $counter = 0;
while (<NEWS>)
{
$lines[$counter] = "$_\n";
$counter++;
}
close NEWS;
print header, "\n";
print "Here is counter $counter\n";
print "here is lines @lines[0]\n";
print start_form, "\n",
br, br, "\n",
"Oracle username: \n",
textarea(-name=>'news_text',
-default=>@lines,
-rows=>40,
-columns=>60), "\n",
br, br, "\n",
submit(-value=>'post news'), "\n",
endform, "\n";
print hr, "\n";
if (param())
{
my @text = param('news_text')
or die "Must have news text\n";
open NEWS, ">news.txt"
or die "Coulden't open news.txt: $!.";
foreach $line (@text)
{
print NEWS "$line\n";
}
}
I'm trying to pull the text from a file in my current directory called news.txt. With that text, i want' to populate a textarea so it is editable. But i can't seem to get all the lines from the file in there.
Any tips?
Heres the code.
#!/usr/local/bin/perl -w
use CGI qw
use CGI::Carp qw(fatalsToBrowser warningsToBrowser carpout);
warningsToBrowser(1); # activate warnings
open NEWS, "<news.txt"
or die "Coulden't open news.txt: $!.";
my $counter = 0;
while (<NEWS>)
{
$lines[$counter] = "$_\n";
$counter++;
}
close NEWS;
print header, "\n";
print "Here is counter $counter\n";
print "here is lines @lines[0]\n";
print start_form, "\n",
br, br, "\n",
"Oracle username: \n",
textarea(-name=>'news_text',
-default=>@lines,
-rows=>40,
-columns=>60), "\n",
br, br, "\n",
submit(-value=>'post news'), "\n",
endform, "\n";
print hr, "\n";
if (param())
{
my @text = param('news_text')
or die "Must have news text\n";
open NEWS, ">news.txt"
or die "Coulden't open news.txt: $!.";
foreach $line (@text)
{
print NEWS "$line\n";
}
}