PDA

View Full Version : Any way I can check my perl program for bugs?


a12bc3
11-05-2004, 04:21 AM
I downloaded a great perl program, but every time I go to run it, it says 500 server error.

I know perl works, cause other scripts work. I know it is this one program :unsure:

Are there any programs to check the program? TIA :)

Silver
11-05-2004, 02:13 PM
Can you just pm me the script, and maybe the error, if possible.
As for scripts which check the error, nope. There are debuggers, but you ofcourse need to correct the errors urself. They just pinpoint the error location, and maybe tips sumtimes.

nkotb131
11-05-2004, 05:20 PM
Originally posted by a12bc3@Nov 5 2004, 12:21 AM
I downloaded a great perl program, but every time I go to run it, it says 500 server error.

I know perl works, cause other scripts work. I know it is this one program :unsure:

Are there any programs to check the program? TIA :)
5892

Another possibility might be that the script you're running did not point to the right directory where either perl is store, or the action script.

Just my 2 cents. I'm new at cgi/perl, too, so I don't know the details.

Can you post the error code?

mahangee
11-05-2004, 05:33 PM
Nope its a server problem if the error posted is correct.

For more info look here http://www.w3schools.com/html/html_httpmessages.asp

Silver
11-06-2004, 12:35 PM
Mahangee, i beg to differ, but NO! Just NO! Mahangee, though its written-> Internal server error, you should know that the server executes cgis by running pipes onto them, hence, an error in the cgi = internal server error. Please try to not misguide.
Firstly, a12bc3, check the chmod of the script, and ensure that it has executable permissions for all groups. I would suggest 755 chmod.
Then, you check out the interpreter path. I myself dont know whether interpreter path is /usr/bin/perl or /usr/local/bin/perl here (you will probably know it in the cpanel or by askin the admin). Now, open the script and check if the first line is #!DIRECTORY where DIRECTORY is either /usr/bin/perl or /usr/local/bin/perl . Correct if its wrong to point to the correct interpreter.
Now, if you know a little bit of PERL, or atleast abt basic programmin, then you can just see the control of the program approx. See the first "CONTROL" occurance of the print statement. (By control, i mean the first occurance during execution, not just line by line).
It should be sumthing like-> print "Content-type: text/html\n\n";
If the prob was solved by above means, that means that the error in the cgi error logs was-> "Premature Termination of Headers" . Its quite common.
Otherwise, there maybe other errors, which may as well be caused cause of the program itself, or not.
Here are sum errors which there might be a chance of seeing in the server cgi error logs-
"Cannot create/open/... FILE: xyz.abc" -> Check the permission of the folder that the script wants to create xyz.abc . It should be writeable.
".....pm module not location in @INC (@INC contains /lib,.....)...." - Check the xyz.pm module name. Try to download it from a place like cpan ( http://search.cpan.org ) and install it in lib using cpanel features (i hope cpanel has it). Otherwise, just add it to the local directory, and use the following immediately after #!/.....
#!/usr/bin/perl # Can be the other directory.
use Cwd;
unshift @INC,cwd();
require xyz.pm
.....
This will let the interpreter look in the local directory for xyz.pm . By default, it should look, but relying on default aint good.

Then, there are many multiple errors which might occur.

a12bc3, i could be able to help you if you could post the error which is shown in the error logs here.

a12bc3
11-11-2004, 12:34 AM
Ok, I'm sorry that I took so long to respond. I've been really busy with school.

I have really chopped the program up. I have changed things, and changed them back. I just hope that I havn't done anything really bad. neways, anything I did, I changed back.

I get 3 errors:
[2004-11-10 17:30:43]: error: directory is writable by others: (/home/abc/public_html/spanish)
[Wed Nov 10 17:30:43 2004] [error] [client 68.120.100.100] File does not exist: /home/abc/public_html/500.shtml
[Wed Nov 10 17:30:43 2004] [error] [client 68.120.100.100] Premature end of script headers: /home/abc/public_html/spanish/spanish.pl

It has the premature script thing you were talking about.

Want me to post the code?

#!/usr/bin/perl

### Spanish Verbal Essence 0.9
### Copyright (C) 2002 David Kamholz <davekam@pobox.com>. Comments welcome.
###
### This program is free software; you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation; either version 2 of the License, or
### (at your option) any later version.
###
### See the included LICENSE file for details.

use strict 'vars';
use vars qw(

$path $mac_chars $latin1_chars $msdos_chars $internal_chars
$vowels $vowels_caps $front_vowels $back_vowels $hiatus_vowels $glide_vowels
$glides $liquids $palatals $V $C %glide %vowel

%endings %tense_info %irregular %pattern %note @forms
$current_tense $infinitive $infinitive_prefix $verb_type $pinfinitive $pstem @syllables $stress $ptense_copy
@stems @endings $thisverb $thistense $output $standard_code

);

$mac_chars = "\x87\x8E\x92\x97\x9C\x9F\x96\xE7\x83\xEA\xEE\xF2\ x86\x84";
$latin1_chars = "\xE1\xE9\xED\xF3\xFA\xFC\xF1\xC1\xC9\xCD\xD3\xDA\ xDC\xD1";
$msdos_chars = "\xA0\x82\xA1\xA2\xA3\x81\xA4\x00\x90\x00\x00\x00\ x9A\xA5";
$internal_chars = 'AEIOUWN';

$vowels = 'aeiou';
$vowels_caps = 'AEIOU';
$front_vowels = 'ei';
$back_vowels = 'aou';
$hiatus_vowels = 'aeo';
$glide_vowels = 'iu';
$glides = 'jw';
$liquids = 'lr';
$palatals = 'NL';
$V = $vowels.$glides;
$C = "^.$V";

%glide = ( 'i' => 'j', 'u' => 'w');
%vowel = reverse %glide;

$path = '';

$standard_code = sub { build_forms() };

open(TENSES, "${path}tenses") or error("Can't find tenses file!"), die;
$current_tense = '';
{ my (@temp, $set, $ending, $num_per_set, @info);
while (<TENSES>) {
chop;

s/^#.*$//; # remove comments
s/^\s+//; # remove spaces
s/\s+$//;
next if $_ eq '';

if (/^=(.+)$/) {
unless ($current_tense eq '') {
$endings{$current_tense} = [ @temp ];
$tense_info{$current_tense}{'stem_type'} = shift @info;
map { $tense_info{$current_tense}{$_} = 1 } @info;
}


($current_tense, $num_per_set, @info) = split(' ', $1);
last if $current_tense eq 'end';

@temp = ();
$ending = $set = 0;

next;
}

if ($ending == $num_per_set) {
$set++;
$ending = 0;
}

push(@{$temp[$set]}, $_);
$ending++;
}
}
close TENSES;

open(IRREGULAR, "${path}irregulars") or error("Can't find irregulars file!"), die;
{ my (@irreg_last, $tense);
while (<IRREGULAR>) {
my ($verb, @irreg, $descrip, $stripped_descrip, @stem, $ref);
chop;

s/#.*$//; # remove comments
s/^\s+//; # remove spaces
s/\s+$//;
next if $_ eq '';

($verb, @irreg) = split(' ');

if ($verb eq 'global') {
@irreg_last = @irreg;
next;
}
elsif (@irreg == 0) {
@irreg = @irreg_last;
}

foreach (@irreg) {
($descrip, @stem) = split(/:/);
$stripped_descrip = $descrip;
$stripped_descrip =~ s/[0-9]+$//;

if ($endings{$stripped_descrip} and @stem == @{$endings{$stripped_descrip}->[0]}) {
$ref = [ @stem ];
}
elsif (@stem == 1) {
$ref = $stem[0];
}
else {
$ref = 1;
}

# verbs beginning with dashes are "pattern verbs"
# they don't have to be verbs themselves; they are the ending
# for example, "olver" for volver, revolver, devolver ...
if ($verb =~ /-(.+)$/) {
$pattern{$1}{$descrip} = $ref;
}
elsif ($verb !~ /^[a-z$internal_chars]+$/) {
error("Invalid irregulars entry: $verb"), die;
}
else {
$irregular{$verb}{$descrip} = $ref;
}
}
}
}
close IRREGULAR;

open(NOTES, "${path}notes") or error("Can't find notes file!"), die;
while (<NOTES>) {
chop;

s/^#.*$//; # remove comments
s/^\s+//; # remove spaces
s/\s+$//;
next if $_ eq '';

$note{$_} = <NOTES>;
}

defined $ENV{'REQUEST_METHOD'} ? cgi_mode() : console_mode();

sub console_mode {
if (@ARGV) {
foreach (@ARGV) {
$infinitive = $_;

local $output;
conjugate_verb();

print "\nVerb: $infinitive\n\n";
# convert_accents_console($output);
$output =~ s/\\//g; # remove escape sequences
print $output;
}
}
else {
for (;;) {
print "Enter an infinitive [return to exit]: ";
chomp ($infinitive = <STDIN>);
last unless $infinitive;

local $output;
conjugate_verb();

print "\n";
# convert_accents_console($output);
$output =~ s/\\//g; # remove escape sequences
print $output;
}
print "\nExiting\n";
}
}

sub cgi_mode {
my ($input, @input, $i, $min);

$input = $ENV{'QUERY_STRING'};
$input =~ /verb=([^&]+)/;
$input = $1;
$input =~ s/\+/ /g;
$input =~ s/%([0-9A-F]{2})/pack("H2", $1)/ge;

print "Content-type: text/html\n\n";
print "<HTML>\n<TITLE>Conjugation of $input</TITLE>\n<FONT SIZE=+1>\n";

@input = split(' ',$input);
$min = @input < 10 ? @input : 10;
for ($i = 0; $i < $min; $i++) {
$infinitive = $input[$i];
local $output;
conjugate_verb() == 0 or next;

my $html_infinitive = $infinitive;
convert_accents_html($html_infinitive);
print "<FONT SIZE=+3><B>Verb: <A HREF=http://www.wordreference.com/es/en/translation.asp?spen=$html_infinitive>$html_infini tive</A></B></FONT><BR><BR>\n";

$output =~ s/\n+/'<BR>' x length($&) . "\n"/ge; # make newlines show up correctly
convert_accents_html($output); # make accents show up correctly
$output =~ s/\\//g; # remove escape sequences
$output =~ s|\*(.+?)\*|<B>$1</B>|g; # bold formatting
$output =~ s|_(.+?)_|<I>$1</I>|g; # italic formatting
$output =~ s|(!+)(.+?)\1|<FONT SIZE=+${\(length($1)+1)}>$2</FONT>|g; # font size formatting
$output =~ s|@(.+?)@|<A HREF="spanish.pl?verb=$1">$1</A>|g; # verb link formatting

print $output;
}

print "</FONT></HTML>\n";
}

sub conjugate_verb {
my ($exception, $code, $stress, @syllables);

# remove white space
$infinitive =~ s/\s+//g;

# translate character sets into internal representation (first line does unicode)
$infinitive =~ tr/\0-\x{ff}//UC;
eval "\$infinitive =~ tr/A-Z$mac_chars$msdos_chars$latin1_chars/a-z" . $internal_chars x 6 . "/";

# no accented vowels
$infinitive =~ tr/'//;
eval "\$infinitive =~ tr/$vowels_caps/$vowels/";

# translate character sequences into internap representation
$infinitive =~ s/u:/W/g;
$infinitive =~ s/n~/N/g;

error("Verb too short!"), return -1 if length($infinitive) < 2;
error("Bad character(s) in verb!"), return -1 if $infinitive !~ /^[a-z$internal_chars]+$/;

$infinitive =~ s/se$//;
if ($exception = $irregular{$infinitive}{'alias'}) {
$infinitive = $exception;
}

$pinfinitive = grapheme_to_phoneme($infinitive);
error("Verb ending not ar/er/ir!"), return -1 if $pinfinitive !~ /[aeiI]r$/;
$verb_type = substr($pinfinitive, -2, 2);

if ($infinitive_prefix = $irregular{$infinitive}{'prefix'}) {
$pinfinitive =~ s/^$infinitive_prefix//;
}
$infinitive = syllables_to_grapheme($infinitive,syllabize($pinfi nitive));
$thisverb = ($irregular{$infinitive_prefix.$infinitive} || $irregular{$infinitive}); # makes things easier
$infinitive = $infinitive_prefix.$infinitive;

# see if it's a pattern verb and if so "install" it
{ my ($pat, $descrip, $prepend);
foreach $pat (keys %pattern) {
if ($infinitive =~ /$pat$/) {
foreach $descrip (keys %{$pattern{$pat}}) {
if (ref $pattern{$pat}{$descrip}) {
next if exists $$thisverb{$descrip};

$$thisverb{$descrip} = [ @{$pattern{$pat}{$descrip}} ];
foreach (@{$$thisverb{$descrip}}) {
$_ = eval qq/"$`$_"/;
}
}
elsif ($pattern{$pat}{$descrip} eq '0') {
# never override an exception of this sort.
$$thisverb{$descrip} = 0;
}
elsif ($pattern{$pat}{$descrip} eq '1') {
$$thisverb{$descrip} = 1 unless exists $$thisverb{$descrip};
}
else {
$$thisverb{$descrip} ||= grapheme_to_phoneme($`).(eval qq/"$pattern{$pat}{$descrip}"/);
}
}
}
}
}

# by default, assume there are underlying glides, unless it is listed as irregular.
# this is not something grapheme_to_phoneme can do for us, because the graphemes are ambiguous.
unless ($$thisverb{'underlying_vowels'}) {
# the following line used to have $vowels instead of $hiatus_vowels but this improperly catches construir and friends.
$pinfinitive =~ s/([$glide_vowels])(?=[$hiatus_vowels])/$glide{$1}/g; # cambiar, etc.
$pinfinitive =~ s/([$vowels])([$glide_vowels])(?=..)/$1$glide{$2}/g; # peinar, etc.
}

# STEM
$pstem = length $infinitive > 2 ? ($$thisverb{'stem'} || substr($pinfinitive,0,-2)) : '';
if ($verb_type eq 'ir' and ($$thisverb{'diphthongization'} or $$thisverb{'raising'}) and not exists $$thisverb{'unstressed_raising'}) {
$$thisverb{'unstressed_raising'} = 1;
}
if ($$thisverb{'velar_extension'}) {
if ($pstem =~ /z$/) {
$$thisverb{'present_subjunctive'} ||= $pstem.'c';
}
elsif ($pstem =~ /[$vowels]$/) {
$$thisverb{'present_subjunctive'} ||= $pstem.'jg';
}
elsif ($pstem =~ /[lns]$/) {
$$thisverb{'present_subjunctive'} ||= $pstem.'g';
}
}

if ($$thisverb{'past_participle2'}) {
$output .= "!*N\\ote:*! $note{'past_part'}\n";
}
if ($exception = $$thisverb{'note'}) {
$output .= "!*N\\ote:*! $note{$exception}\n";
}

# PRESENT PARTICIPLE
build_tense('present_participle');

# PAST PARTICIPLE
build_tense('past_participle');

# PRESENT INDICATIVE
$code = sub {
if ($forms[0] = $thistense) {
undef $thistense;
}
elsif ($exception = $$thisverb{'present_subjunctive'}) {
$stems[0] = $exception;
}
build_forms();
};
build_tense('present_indicative', $code);

# PRETERITE
$code = sub {
$verb_type = 'ir' if ($thistense or $infinitive eq 'dar');

if ($thistense) {
$endings[0] = 'e';
$endings[2] = 'o';
$endings[5] = 'eron' if $thistense =~ /x$/;
}

build_forms();

map { s/[$vowels_caps]/\u$&/o } @forms if $thistense;
};
build_tense('preterite', $code);

# IMPERFECT
build_tense('imperfect');

# FUTURE
build_tense('future');

# CONDITIONAL
if ($exception = $$thisverb{'future'}) { # it is irregular the same way as future
$$thisverb{'conditional'} = $exception;
}
build_tense('conditional');

# PRESENT SUBJUNCTIVE
build_tense('present_subjunctive');

# IMPERFECT SUBJUNCTIVE
$$thisverb{'imperfect_subjunctive'} ||= $$thisverb{'preterite'};
$code = sub {
$verb_type = 'ir' if ($thistense or $infinitive eq 'dar');
build_forms();

if ($thistense =~ /x$/) {
foreach (@forms) { s/ji(?=[eE])/j/; }
}
elsif ($infinitive eq 'ir' or $infinitive eq 'ser') {
foreach (@forms) { s/uy(?=[eE])/u/; }
}

};
build_tense('imperfect_subjunctive', $code);

# IMPERATIVE
$code = sub {
$forms[0] = $thistense;
$thistense = undef;

build_forms();
};
build_tense('imperative', $code, '(tU)', '(vosotros)');

return 0;
}

sub build_forms {
my ($i, $ptense);
my ($stressed_code, $unstressed_code, $yod_extension_code);

my $regular_endings = get_regular_endings();
my $num_endings = @{$regular_endings};
for ($i = 0; $i < $num_endings; $i++) {
$endings[$i] ||= $regular_endings->[$i];
}

$stressed_code = $unstressed_code = $yod_extension_code = sub {};

# unless it's an irregular stem
unless ($ptense = $thistense) {
$ptense = $tense_info{$current_tense}{'stem_type'} eq 'infinitive' ? $pinfinitive : $pstem;

if ($tense_info{$current_tense}{'stressed_changes' }) {
if ($$thisverb{'diphthongization'}) {
$stressed_code = sub {
$syllables[$stress] =~ s/[ei]/je/ or $syllables[$stress] =~ s/[ou]/we/;
};
}
elsif ($$thisverb{'raising'}) {
$stressed_code = sub {
$syllables[$stress] =~ s/e/i/ or $syllables[$stress] =~ s/o/u/;
};
}
}

if ($tense_info{$current_tense}{'unstressed_change s'} and $$thisverb{'unstressed_raising'}) {
$unstressed_code = sub {
if ($syllables[$stress-1] =~ s/e/i/) {
$syllables[$stress-1] =~ s/i$// if $syllables[$stress] =~ /^j/;
}
else {
$syllables[$stress-1] =~ s/o/u/;
}
};
}

if ($tense_info{$current_tense}{'yod_extension'} and $$thisverb{'yod_extension'}) {
$yod_extension_code = sub {
$_[0] .= 'j' if $_[1] =~ /^[aeo]/;
}
}
}

for ($i = 0; $i < @endings; $i++) {
next if $forms[$i];

local ($stress,@syllables);
local $ptense_copy = $ptense;
{ if ($stems[$i]) {
($stress,@syllables) = syllabize($stems[$i].$endings[$i]);
last;
}

&$yod_extension_code($ptense_copy,$endings[$i]) ;

($stress,@syllables) = syllabize($ptense_copy.$endings[$i]);
if ($endings[$i] =~ /^(A|j[$vowels_caps])/o) {
&$unstressed_code;
}
elsif ($endings[$i] !~ /[$vowels_caps]/o) {
&$stressed_code;
} }

$forms[$i] = syllables_to_grapheme($infinitive,$stress,@syllabl es);
}

if ($infinitive_prefix) {
@forms = map { $_ = $infinitive_prefix.$_ } @forms;
}
}

# build_tense general_tense, code, label1, label2, ... label6
# searches for general_tense or general_tense1, general_tense2, general_tense3, ...
sub build_tense {
$output .= format_tense($_[0])."\n\n";

my ($i, @tenses, @compound_storage);
if ($endings{$_[0].'1'}) {
push(@tenses, $_[0].'1');
for ($i = 2;;$i++) {
$endings{$_[0].$i} ? push(@tenses, $_[0].$i) : last;
}
}
else {
push(@tenses, $_[0]);
for ($i = 2;;$i++) {
$$thisverb{$_[0].$i} ? push(@tenses, $_[0].$i) : last;
}
}

my $code = $_[1] || $standard_code;
foreach (@tenses) {
local $verb_type = $verb_type;

set_tense($_,$_[0]) and &$code;
for ($i = 0; $i < @forms; $i++) {
push(@{$compound_storage[$i]}, $forms[$i]);
}
}

for ($i = 0; $i < @compound_storage; $i++) {
$output .= join(' or ', @{$compound_storage[$i]});
$output .= " $_[$i+2]\n";
}

$output .= "\n";
}

# set_tense actual_tense, general_tense
# returns true if the verb needs to be put together: i.e. is not totally
# irregular like ser, ir, etc.
# this is the only sub that is called *every* time for every tense
sub set_tense {
$current_tense = $_[0];

$thistense = $endings{$_[0]} ? $$thisverb{$_[1]} : $$thisverb{$_[0]};
if (ref $thistense) {
@forms = @{$thistense};
return 0;
}
@forms = @stems = @endings = ();
return 1;
}

# verb_index num_ending_varieties
sub verb_index {
if ($_[0] == 3) {
return 0 if $verb_type eq 'ar';
return 1 if $verb_type eq 'er';
return 2;
}
elsif ($_[0] == 2) {
return 0 if $verb_type eq 'ar';
return 1;
}
return 0;
}

sub get_regular_endings {
return \@{$endings{$current_tense}[ verb_index(scalar @{$endings{$current_tense}}) ]};
}

sub error {
print "Error: $_[0]\n";
}

# phonemes: a b c d e f g i j J l L m n o p r R s t T u v x X w z
# /L/ = <ll>; /R/ = <rr>; /T/ = <ch>; /x/ = <j>; /X/ = <g> before <e,i>;
# /c/ = <c> before <a,o,u>, <qu> elsewhere; /z/ = <c> before <e,i>, <z> elsewhere.
# /j/ and /w/ are the glide forms of /i/ and /u/; they do indeed contrast phonemically.
# a purely phonemic system is not quite ideal because certain things in the orthography contrast
# while not constrasting phonemically, so we have <j,g> before <e,i>; <b,v>; and <h>.
# there's no harm in our situation of maintaining different phonemes for <b,v>.
# <j,g> is only slightly annoying, care must simply be taken to always check for either /x/ or /X/,
# as they are technically the same phoneme.
# <h> is problematic because it is not pronounced.

sub grapheme_to_phoneme {
$_ = $_[0];

s/rr/R/g;
s/ll/L/g;
s/ch/T/g;
s/x/cs/g;
s/j/x/g;
s/y/j/g;
s/h//g;

s/g(?=[$front_vowels])/X/gio;
s/gu(?=[$front_vowels])/g/gio;
s/gu(?=[$back_vowels])/gw/gio;
s/gW/gu/g;

s/c(?=[$front_vowels])/z/gio;
s/qu/c/gi;

return $_;

# the following used to be in this function. it is still useful if it's ever necessary to
# systematically refine the phonemes further after syllabization.
# my ($stress,@syllables) = syllabize($_);
# foreach (@syllables) {
# s/([$glide_vowels])([$vowels])/$glide{$1}$2/go;
# s/([$hiatus_vowels])([$glide_vowels])/$1$glide{$2}/go;
# s/([$palatals])j/$1/go;
# }
#
# return ($stress,@syllables);
}

sub syllables_to_grapheme {
my ($original,$stress,@syllables) = @_;

if (@syllables > 1) {
# accent to clarify hiatus or glide situation
if ( $stress != -1 and has_glide(@syllables[$stress,$stress+1]) <= 2 or
$stress != -@syllables and has_glide(@syllables[$stress-1,$stress]) <= 2)
{
$syllables[$stress] =~ s/[$glide_vowels]/\u$&/ unless $syllables[$stress] =~ s/[$hiatus_vowels]/\u$&/;
}
# accent on "less common" place in word (as dictated by orthography)
elsif ($stress < -2 or $stress == -2 and $syllables[-1] !~ /[ns$vowels]$/
or $stress == -1 and $syllables[-1] =~ /[ns$vowels]$/)
{
$syllables[$stress] =~ s/[$glide_vowels]/\u$&/ unless $syllables[$stress] =~ s/[$hiatus_vowels]/\u$&/;
}
}

$_ = join('', @syllables);

s/([$vowels])j(?=[$vowels])/$1y/gio;
eval "tr/$glides/$glide_vowels/";

s/c(?=[$front_vowels])/qu/gio;
s/gu(?=[$front_vowels])/gW/gio;
s/g(?=[$front_vowels])/gu/gio;
s/z(?=[$front_vowels])/c/gio;

s/R/rr/g;
s/L/ll/g;
s/T/ch/g;
s/x/j/g;
s/X(?=[$back_vowels])/j/gio;
s/X/g/g;
s/cs/x/g;

# get our <h>'s straight.
while ($original =~ /^(.*?)h/g) {
my $length = length $1;
next if substr($_,$length,1) eq 'h';
substr($_,$length,1) = 'h'.substr($_,$length,1);
}

# must do this *after* we get our <h>'s straight.
s/^u(?=[$vowels])/hu/;
s/^i(?=[$vowels])/y/;
s/hy/hi/g; # digraph representation of syllable-initial /j/

return $_;
}

sub syllabize {
$_ = $_[0];

# the following handles yod absorption, a phonological process which probably does not
# belong in the syllabizer, but this is the most convenient place to put it.
# unlike when a vowel turns into a glide, making this change will cause no problems.

s/([$palatals])j/$1/go;

# the following splits all underlying vowels. they will be joined in a diphthong later if necessary.
# note that we are not worrying about accents here, they are merely orthographic
# and will also be inserted later if necessary.

s/([$vowels])(?=[$vowels])/$1./gi;
s/([$vowels])(?=[$glides][$vowels])/$1./gi;

# the following handles all consonant clusters. to be safe, we make sure we're handling them
# of the highest magnitude in the word; if each were hard-coded we might miss one, and anyway,
# this seems both more efficient to code and more elegant.

my ($stress, $max, $i); $max = 0;
while (/[$C]+/g) {
my $len = length $&;
$max = $len if $len > $max;
}

# VCxV
for ($i = $max; $i > 1; $i--) { # ignore the hideous syntax, please
s/([$V][$C]{${\($i-2)}})(?=[$C][$liquids][$V])/$1./gi;
s/([$V][$C]{${\($i-1)}})(?=[$C][$V])/$1./gi;
}

# VCV
s/([$V])(?=[$C][$V])/$1./gi;

my @syllables = split('\.', $_);
for ($i = 0; $i < @syllables; $i++) {
if ($syllables[$i] =~ /[$vowels_caps]/o) {
$syllables[$i] =~ s/[$vowels_caps]/\l$&/;
$stress = $i - @syllables;
last;
}
}

if (not defined $stress) {
$stress = @syllables == 1 ? -1 : ($syllables[-1] =~ /[ns$vowels]$/o ? -2 : -1);
}
if ($stress != -@syllables and has_glide(@syllables[$stress-1,$stress]) == 1) {
splice(@syllables,$stress-1,2,$syllables[$stress-1].$syllables[$stress]);
}
for ($i = 0; $i < $#syllables + $stress; $i++) {
splice(@syllables,$i,2,$syllables[$i].$syllables[$ i+1]) if has_glide(@syllables[$i,$i+1]) != 4;
}

return ($stress,@syllables);
}

# returns 1 (left-glide only), 2 (right-glide only), 3 (both), or 4 (neither)
# it does not return 0 for neither so you can check <= 2 to check "one glide but not two"
sub has_glide {
return 4 if $_[0] !~ /[$vowels]$/o or $_[1] !~ /^[$vowels]/o;

my $glides = 0;
$glides |= 1 if $_[0] =~ /[$glide_vowels]$/o;
$glides |= 2 if $_[1] =~ /^[$glide_vowels]/o;
return $glides if $glides > 0;
return 4;
}

# format_tense tense
sub format_tense {
my $tense_formatted = $_[0];
$tense_formatted =~ s/_/ /g;
$tense_formatted =~ s/\b(.)/\u$1/g;
$tense_formatted =~ s/[$internal_chars]/$&\\/g;
return "!*$tense_formatted*!";
}

# convert_accents data
# this is so the accents will work in html
sub convert_accents_html {
$_[0] =~ s/A(?!\\)/&aacute;/g;
$_[0] =~ s/E(?!\\)/&eacute;/g;
$_[0] =~ s/I(?!\\)/&iacute;/g;
$_[0] =~ s/O(?!\\)/&oacute;/g;
$_[0] =~ s/U(?!\\)/&uacute;/g;
$_[0] =~ s/W(?!\\)/&uuml;/g;
$_[0] =~ s/N(?!\\)/&ntilde;/g;
}

sub convert_accents_console {
my @chars = split //, $mac_chars;
$_[0] =~ s/A(?!\\)/$chars[0]/go;
$_[0] =~ s/E(?!\\)/$chars[1]/go;
$_[0] =~ s/I(?!\\)/$chars[2]/go;
$_[0] =~ s/O(?!\\)/$chars[3]/go;
$_[0] =~ s/U(?!\\)/$chars[4]/go;
$_[0] =~ s/W(?!\\)/$chars[5]/go;
$_[0] =~ s/N(?!\\)/$chars[6]/go;
}

That is it. BTW, thanks a bunch Silver for giving helping me so far ^_^

Also, there are 3 other files that are needed with the program: tenses, irregular, and notes. Lower case.

Also, in the readme file
Originally posted by "README"
Usage
=====

This is a script that will conjugate spanish verbs. It may run either as a
cgi script (taking a text string 'verb') or from the command line. The mode
is auto-detected by checking if the environment variable REQUEST_METHOD
exists.

Any number of infinitives may be specified as command line arguments. The
verbs will be conjugated and the script will exit. If no arguments are
given, a prompt is provided to input infinitives.

The command line output shows accented vowels as uppercase, and an en~e as
uppercase N.

Silver
11-18-2004, 06:19 PM
heh, the error is quite simple. The directory permission, mainly the script permission is sumthing like 777 or sumthing? Suggest that you change it to 755, cause that denies external writablity.
The 500.shtml not found is just saying that the document wasnt found, goodness knows why. Thats just for the error page.
The Premature Termination of Headers, in this case is because the script never really executed.

Just changing the permission should do.

a12bc3
12-30-2004, 10:59 AM
I never got this bitch to work. What I did was use a telnet service thing to find the errors. It came up with the following:

Bareword found where operator expected at spanish.pl line 222, near "tr/\0-\x{ff}//UC"
syntax error at spanish.pl line 222, near "tr/\0-\x{ff}//UC"
Execution of spanish.pl aborted due to compilation errors.

That's what it told me, can you interpret it please Silver?

Silver
01-05-2005, 11:51 AM
See the line $infinitive =~ tr/\0-\x{ff}//UC;
Try to make it-
$infinitive =~ tr/\0-\x{ff}//s;
It should work, but I didnt have time to read the whole program. If that doesnt work (logical error), just try
$infinitive =~ tr/\0-\x{ff}//cs;
$infinitive =~ tr/\0-\x{ff}//d;
$infinitive =~ tr/\0-\x{ff}//cd;
$infinitive =~ tr/\0-\x{ff}//;

If it still doesnt work, then I seriously need to sit down and read the full source.

a12bc3
01-22-2005, 07:26 PM
Man, you wouldn't have to read the whole source. You know why? Cuz it works :-P well, I had it working before. all i did was put a "#" before that line. it worked, so i didn't worry about it. now i took that off and changed the UC > s. it still works. so thanks man!!

if you want to see it in action, go here: http://www.ninjahideout.net/conjugator/

Silver
01-23-2005, 06:47 AM
Putting a # before a line just makes it a comment. And unless that line is soo essential that the script doesnt run without it, well, thats got me stumped on how.
Hey, are you talking abt before #!/usr/bin/perl u put a # ?
Also, what abt this error-
Bareword found where operator expected at spanish.pl line 222, near "tr/\0-\x{ff}//UC"
syntax error at spanish.pl line 222, near "tr/\0-\x{ff}//UC"
Execution of spanish.pl aborted due to compilation errors.
This shouldnt work by only addition or removal of a # .