LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl compilation error (https://www.linuxquestions.org/questions/programming-9/perl-compilation-error-794123/)

smeezekitty 03-09-2010 12:04 AM

Perl compilation error
 
I get an error when typing perl build.pl:
Code:

Cannot locate Unicode/String.pm in @INC

chrism01 03-09-2010 12:35 AM

You should get a much longer output than that.. it usually says what @INC consists of ie the list of known dirs to look in for reqd modules/fns.
It's basically saying you've called the Unicode:String sub, but it can't find the file containing the definition.

smeezekitty 03-09-2010 01:07 AM

Cant locxte Unicode/String.pm in @INC (@INC contains: ./lib /etc/perl/lib/perl/5.100.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl/5.10 .)

theNbomr 03-09-2010 09:07 AM

It says that it expects a module Unicode::String to be founds in one of the 'usual places', but that it isn't found there. If you have actually installed it somewhere else, you can add to your main package
Code:

use lib '/the/dir/where/it/is';
Put the 'use lib' directive above the statement that loads the module.
If you haven't installed the module, then the CPAN installer will probably put it in the proper place among the list of 'usual places'.

--- rod.

smeezekitty 03-09-2010 12:15 PM

I solved the first error by typing
Code:

cpan --install Unicode::String
But now there is another error:
Code:

Prototype mismatch: sub AIML::Common::LOCK_UN () vs none at lib/AIML/Common.pm line 55.


Died at lib/AIML/Unicode.pm line 102.
Compilation failed in require at lib/AIML/Common.pm line 109.
BEGIN failed--compilation aborted at lib/AIML/Common.pm line 109.
Compilation failed in require at build.pl line 32.
BEGIN failed--compilation aborted at build.pl line 32.

Unicode.pm:
Code:

=head1 NAME

AIML::Unicode - Functions for UTF8 String Case Changing

=head1 SYNOPSIS

  $upper    = uppercase ( 'uppercase' );            # returns 'UPPERCASE'
  $lower    = lowercase ( 'lOwErCaSe' );            # returns 'lowercase'
  $formal  = formal    ( 'proper name' );          # returns 'Proper Name'
  $sentence = sentence  ( 'this is a sentence' );  # returns 'This is a sentence'

=head1 DESCRIPTION

This module provides functions to change the case of UTF8 strings.

=cut

package AIML::Unicode;

use strict;
use warnings;

BEGIN
{
        use vars qw ( $VERSION $DEBUG %CONSTANTS );

        $VERSION        = $VERSION        = 0.08;

        $DEBUG        = 0        unless $DEBUG;
}

use utf8;
use charnames ':full';

use Unicode::String                ();
use Unicode::CharName        ();
use Unicode::Map8                        ();

use EnglishSave;

=head1 GLOBALS

  $AIML::Unicode::DEBUG = 1;

No debugging functionality provided yet.

=head1 EXPORT

=head2 Public Functions

C<uppercase>, C<lowercase>, C<formal>, C<sentence>

=cut

sub import
{
        no strict qw ( refs );

        my $callerpkg = caller(0);

        #        export functions
        #
        *{"$callerpkg\::uppercase"}                        = *uppercase;
        *{"$callerpkg\::lowercase"}                        = *lowercase;
        *{"$callerpkg\::formal"}                                = *formal;
        *{"$callerpkg\::sentence"}                                = *sentence;

        1;
}

#
#        PRIVATE VARS
#
my ( $TO_UPPER, $TO_LOWER, $TO_TITLE, $TO_DIGIT );

$TO_UPPER        = _load_case ( 'unicode/To/Upper.pl' );
$TO_LOWER        = _load_case ( 'unicode/To/Lower.pl' );
$TO_TITLE        = _load_case ( 'unicode/To/Title.pl' );

#        MEMO:        unicode/To/Digit.pl

=head1 FUNCTIONS

Do not overwrite and call functions marked as I<B<PRIVATE>> from outside.

=over 4

=cut

=pod

=item * _load_case ( $package ) I<PRIVATE>

This function loads the necessary case change tables at compile time.

=cut

sub _load_case
{
        my $pkg = shift;

        my $changer = do ( $pkg ) or die;

        my @lines = split /\n/, $changer;

        $changer = {};

        foreach my $line ( @lines )
        {
                my ( $key, $border, $value )        = split /\t/, $line;

                $key                ||= 0;
                $border        ||= 0;
                $value        ||= 0;

                $key                = hex $key;
                $border        = hex $border;
                $value        = hex $value;

                if ( $border )
                {
#                        printf "$pkg\tk=0x%04x\tb=0x%04x\tv=0x%04x\n",
#                                $key, $border, $value;

                        my $offset = $key - $value;

                        foreach my $key2 ( $key .. $border )
                        {
#                                printf "\tborder\tk=0x%04x\to=0x%04x\tv=0x%04x\n",
#                                        $key2, $offset, $key2 - $offset;

                                $changer->{$key2} = $key2 - $offset;
                        }
                }
                else
                {
#                        printf "$pkg\tk=0x%04x\tb=0x%04x\tv=0x%04x\n",
#                                $key, $border, $value;
#
#                        printf "\t\t\t\tk=0x%04x\to=0x%04x\tv=0x%04x\n",
#                                $key, 0, $value;

                        $changer->{$key} = $value;
                }
        }

#        use Data::Dumper;
#        print "\n$pkg\n", Dumper ( $changer ), "\n";

        return $changer;
}

=pod

=item * uppercase ( $string )

Returns a case changed string.

'uppercase'        becomes        'UPPERCASE'

See L<http://alicebot.org/TR/2001/WD-aiml/#section-uppercase>.

=cut

sub uppercase
{
        return _change_case ( shift(), $TO_UPPER );
}

=pod

=item * lowercase ( $string )

Returns a case changed string.

'lOwErCaSe'        becomes        'lowercase'

See L<http://alicebot.org/TR/2001/WD-aiml/#section-lowercase>.

=cut

sub lowercase
{
        return _change_case ( shift(), $TO_LOWER );
}

=pod

=item * _change_case ( $string ) I<PRIVATE>

The secret worker.

=cut

sub _change_case
{
        my $str_in        = shift;
        my $changer        = shift() || {};

        return ''                unless defined $str_in;

        my $str_out = '';

        my $str_obj = Unicode::String::utf8 ( $str_in );

        my @char_list = $str_obj->unpack;

        my ( $char_in, $char_out );

        foreach $char_in ( @char_list )
        {
                if ( $char_out = $changer->{$char_in} )
                {
                        $str_out .= Unicode::String::uchr ( $char_out );

#                        printf "found\t0x%04x\t0x%04x\t'%s'\n", $char_in, $char_out, $str_out;
                }
                else
                {
                        $str_out .= Unicode::String::uchr ( $char_in );

#                        printf "as is\t0x%04x\t0x%04x\t'%s'\n", $char_in, 0, $str_out;
                }
        }

        return "$str_out";        #        !!!
}

=pod

=item * formal ( $string )

Returns a case changed string.

'proper name'        becomes        'Proper Name'

See L<http://alicebot.org/TR/2001/WD-aiml/#section-formal>.

=cut

sub formal
{
        my $str_in        = shift;

        return ''                unless defined $str_in;

        my @words = split / /, $str_in;

        foreach my $word ( @words )
        {
                my $u = Unicode::String::utf8 ( $word );

                my $first        = $u->substr ( 0, 1 );
                my $rest                = $u->substr ( 1 );

                $first        = ''                unless defined $first;
                $rest                = ''                unless defined $rest;

                $word = _change_case ( "$first", $TO_TITLE ) . _change_case ( "$rest", $TO_LOWER );        #        !!!
        }

        return join ( ' ', @words );
}

=pod

=item * sentence ( $string )

Returns a case changed string.

'this is a sentence'        becomes        'This is a sentence'

'dies ist ein Satz'        becomes        'Dies ist ein Satz' (!)

See L<http://alicebot.org/TR/2001/WD-aiml/#section-sentence>.

=cut

sub sentence
{
        my $str_in        = shift;

        return ''                unless defined $str_in;

        my $u = Unicode::String::utf8 ( $str_in );

        my $first        = $u->substr ( 0, 1 );
        my $rest                = $u->substr ( 1 );

        $first        = ''                unless defined $first;
        $rest                = ''                unless defined $rest;

        return _change_case ( "$first", $TO_UPPER ) . "$rest";        #        !!!
}


=pod

=back

=head1 AUTHOR / COPYRIGHT

Ernest Lergon, L<ernest@virtualitas.net>.

Copyright (c) 2002 by Ernest Lergon, VIRTUALITAS Inc.
L<http://www.virtualitas.net>

AIML - Artificial Intelligence Markup Language
Copyright (c) 1995-2002, A.L.I.C.E. AI Foundation
L<http://www.alicebot.org>

All Rights Reserved. This module is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

If you have suggestions for improvement, please drop me a line.  If
you make improvements to this software, I ask that you please send me
a copy of your changes. Thanks.

=head1 SEE ALSO

L<AIML::Parser>, L<AIML::Loader>, L<AIML::Responder> and L<AIML::Graphmaster>.

=cut

1;

__END__


theNbomr 03-09-2010 06:23 PM

Ouch. That doesn't look too promising. I don't think you've supplied a sample of the right module to get to the bottom of the problem, but from where I sit, that is fairly obscure error message. It looks like a subroutine in one of the modules you are calling has been prototyped more than once and the two prototypes differ. You may have to modify installed code to fix this. I wonder if there is a bug fix published for this.
Maybe try contacting the original author if you got this from CPAN.
--- rod.

smeezekitty 03-10-2010 11:05 AM

Quote:

Originally Posted by theNbomr (Post 3892187)
Maybe try contacting the original author if you got this from CPAN.
--- rod.

Cannot, its not available any more.
I downloaded with the internet archive.

smeezekitty 03-10-2010 05:58 PM

code can be downloaded from http://web.archive.org/web/200705020...net/perl/aiml/

theNbomr 03-10-2010 06:06 PM

Quote:

Originally Posted by smeezekitty (Post 3893066)
Cannot, its not available any more.
I downloaded with the internet archive.

I guess that makes you the maintainer... :)

Seriously, though, have a look at Common.pm, line 55, and line 109. These seem to be of interest to the compiler. I'm guessing one of them is a subroutine, or a subroutine prototype.

--- rod.

smeezekitty 03-10-2010 06:21 PM

Lines of common.pm have an odd construct on lines 39-56:
Code:

eval
        {
                require Fcntl;
                Fcntl->import ( ':flock' );
        };
        my $err1 = $@ || '';

        my $err2 = not exists &flock;

        if ( $err1 or $err2 )
        {
                *CORE::GLOBAL::flock                = sub { 1 };

                *AIML::Common::LOCK_SH        = sub { 1 };
                *AIML::Common::LOCK_EX        = sub { 2 };
                *AIML::Common::LOCK_NB        = sub { 4 };
                *AIML::Common::LOCK_UN        = sub { 8 };
        }

as for 109:
Code:

use AIML::Unicode;

theNbomr 03-11-2010 11:20 AM

Quote:

Originally Posted by smeezekitty (Post 3893542)
Lines of common.pm have an odd construct on lines 39-56:

You're right. I can't make any sense of it. I think you might be best served by inquiring on a Perl-specific forum. In any case, I think the solution will involve scrutiny of a larger sample of the code. Good luck.

--- rod.

Sergei Steshenko 03-11-2010 02:14 PM

Quote:

Originally Posted by theNbomr (Post 3894472)
You're right. I can't make any sense of it. I think you might be best served by inquiring on a Perl-specific forum. In any case, I think the solution will involve scrutiny of a larger sample of the code. Good luck.

--- rod.

The code posted here doesn't have line numbers in it - the latter can be obtained by using 'cat -n some_file'.

Maybe the lines are not that strange, I just don't know what they are.

Kirsle 12-02-2014 11:16 PM

I'm aware this is an old thread, but if anyone else takes an interest in ProgramV and stumbles upon this in the future... I've updated ProgramV's code to run on modern Perl (5.8 through 5.18 and onwards). I have a fork of ProgramV on GitHub: https://github.com/kirsle/programv


All times are GMT -5. The time now is 03:30 AM.