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: Error Message: Variable "@ADDNEWS" is not imported at ...: Edit Log



Larkdog
User

Jun 25, 2004, 7:35 PM


Views: 3603
Error Message: Variable "@ADDNEWS" is not imported at ...

Hello,

I have a small script below that was working until I made a slight change... The script opens and edits a file, formerly called 'home.htm' but now called 'home.php'...when i changed the file extension from .htm to .php, i must have done something else inadvertantely, b/c now it dont work...i even tried to put it back to .htm and it still wont work...could you help find my mistake??? this is the error message i get: Global Variable "@ADDNEWS" is not imported at ... then it gives the location of the file on my pc

here is the script:


Code
    

#!/usr/bin/perl

use warnings;

use strict;

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

$|++;

use CGI::Carp qw(fatalsToBrowser);

$addnews_file = '/home.htm';

if($ENV{'REQUEST_METHOD'} eq "POST"){

$data_length = $ENV{'CONTENT_LENGTH'};

$bytes_read = read(STDIN, $my_data, $data_length);

}

@name_value_array = split(/&/, $my_data);

foreach $name_value_pair (@name_value_array) {

($name, $value) = split(/=/, $name_value_pair);

$name =~ tr/+/ /;

$value =~ tr/+/ /;

$name =~ s/%(..)/pack("C",hex($1))/eg;

$value =~ s/%(..)/pack("C",hex($1))/eg;

if($form_data{$name})

{

$form_data{$name} .= "\t$value";

}

else

{

$form_data{$name} = $value;

}

}

open(ADDNEWS, "<$addnews_file") or

die "Can't open ADDNEWS: $addnews_file\n";

@ADDNEWS =<ADDNEWS>;

close(ADDNEWS);

open(ADDNEWS, ">$addnews_file") or

die "Can't open ADDNEWS: $addnews_file\n";

foreach $line (@ADDNEWS){

if($line =~ /<!--Add News:-->/i) {

print ADDNEWS "<!--Add News:-->\n";

print ADDNEWS "<tr><td>\n";

print ADDNEWS "$form_data{'news'}\n";

print ADDNEWS "</td></tr>\n";



} else {

print ADDNEWS "$line";



close(ADDNEWS);







print <<"EOF"

<HTML><TITLE>Entry Submitted</TITLE><HEAD> <META HTTP-EQUIV="refresh" content="4;URL=../home.htm"></HEAD><BODY>



<H1>Your News Entry has been Submitted\!</H1>

Your news entry has been successfully added to the

ICE homepage and in <font size=24>3</font> seconds you will be taken back to view it.

</BODY>

EOF

#===========================



thanks!
www.MrLarkins.com

(This post was
edited by Larkdog on Jun 26, 2004, 6:19 PM)


Edit Log:
Post edited by Larkdog (User) on Jun 26, 2004, 6:19 PM


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

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