
perlfarmer
User
Aug 8, 2011, 12:11 AM
Post #1 of 3
(384 views)
|
|
"Unknown error"
|
Can't Post
|
|
Hi, I have written a perl script for a web page, get_text.pl, in directory dir that requires Analyze.pm (on line 6) in dir/cg-bin. No matter how I specify the path name for the "require" directive I get:
Unknown error Compilation failed in require at get_text.pl line 6. Here are the first 6 lines:
#!/usr/bin/perl use strict; use CGI::Carp qw(fatalsToBrowser); require "Analyze.pm"; The only thing I can think of is that there is a problem with the .pm file. Here it is:
use strict; use warnings; use GD::Graph; sub analyze { #my $k = shift(@_); my $input = ""; open (INPUT, "<", "text.txt") or &error("System Error: Could not open internal file for reading."); while (<INPUT>) { $input .= $_; } # Strip tags. $input =~ s/<.*>//m; # Replace all whitespace with a single space. $input =~ s/\s/ /m; # Get an array of all the words. my @words = split(/ /, $input); # Hash the words by counting their occurrences. my %wordsHash = (); foreach (@words) { # Strip any punctuation that came with the word. $_ =~ s/[\.\?:;!,\(\)\-\*\[\]]*//; if (wordsHash{$_}) { $wordsHash{$_}++; } else { $wordsHash{$_} = 1; } } my %charsHash = (); foreach (@words) { my @chars = split(//, $_); foreach (@chars) { if ($_ =~ /[A-Za-z]/) { if ($charsHash{$_}) { $charsHash{$_}++; } else { $charsHash{$_} = 1; } } } } my $numSentences = 0; foreach (@words) { $_ =~ s/[\(\)]*//; if ($_ =~ /\w*[\.\?!]*/) { $numSentences++; } } my $numWords = scalar(@words); my $numUniqueWords = keys(%wordsHash); my $numEnglishCharacters = 0; my $key; my $value; while (($key, $value) = each %charsHash) { if ($key =~ /[A-Za-z]/) { $numEnglishCharacters += $value; } } my %freqHash = (); while (($key, $value) = each %charsHash) { if ($key =~ /[A-Za-z]/) { $freqHash{$key} = $value/$numEnglishCharacters; } } my @numData = (["Sentences", "Words", "Unique Words", "English Characters"], ["$numSentences", "$numWords", "$numUniqueWords", "$numEnglishCharacters"]); my $mygraph = GD::Graph::bars->new(500, 300); my $myimage = $mygraph->plot(\@numData) or &error("System Error: Could not plot graph"); print "Content-type: text/html\n\r\n\r"; print "<html><head><body>\n"; print "<h2>Hello World!!!</h2>"; print "</body></head></html>\n"; } sub error { my $message = shift(@_); print "Content-type: text/html\n\r\n\r"; print "<html><head><body>\n"; print "<div align=\"center\"><h2>Error</h2></div>"; print "<div align=\"center\">$message</div>"; print "<br><br>"; print "<div align=\"center\"><form>"; print "<input type=\"button\" value=\"Back\" onclick=\"window.location.href='http://www.kevin.thegreenage.org/public_html/index.html'\">"; print "</form></div>"; #print "<div align=\"center\"><a href=\"http://www.kevin.thegreenage.org/public_html/index.html\">Back to Main Page</a><div>"; print "</body></head></html>\n"; } 1; Can anyone see a reason why this .pm would cause the "unknown error" and cause the compilation to fail? Any advice is appreciated. Regards.
(This post was edited by perlfarmer on Aug 8, 2011, 12:55 AM)
|