Problem loading modules in Perl mysql

1

This time I have a problem with Perl.

I'm making a connection from BD to Perl, but at the time of wanting to connect, it handles some errors.

The getAll code:

#!/usr/bin/perl
use CGI;

# Por si hay errores, esto funciona
use CGI::Carp qw(fatalsToBrowser);

use Template;
use Conexiones;
use utf8;

# Acerca de Perl:
# http://perldoc.perl.org/CGI.html
# https://metacpan.org/pod/CGI
$query = CGI::new();

my $dbh = conectar();
$sth = $dbh->prepare("select * from Peliculas");
$sth->execute() or die $DBI::errstr;

my $vars  = {
    resultado => $sth->fetchall_arrayref([])
    };

my $template = Template->new(
    {
    ENCODING => 'utf8',
    PRE_PROCESS  => 'templates/header.html',
    POST_PROCESS => 'templates/footer.html',
    }
);
my $input = 'templates/index.html';

$template->process($input, $vars) || die $template->error();

$sth->finish();
$dbh->disconnect;

And the Connections module.pm that fails when I execute it:

#!/usr/bin/perl

# se crea un paquete
package Conexiones;

# módulo para desplegar errores
use CGI::Carp qw(fatalsToBrowser);

# El controlador de mysql
# documentación DBI:
# https://metacpan.org/pod/DBI
# http://www.perltutorial.org/perl-dbi/
use DBI;
use DBD::mysql;

# Exportas las variables del modulo
use Exporter;

# permite asociar el paquete declarado por el alumno como 'parte' del
# módulo Exporter, en término de POO se diría que el módulo 
# 'conexiones' es una subclase de Exporter
@ISA = qw(Exporter);

# las variables y funciones se exportan a través del arreglo @EXPORT
# es decir aqui se declaran todas las funciones que se deseen
@EXPORT = qw (conectar);

# documentación para Exporter:
# https://perldoc.perl.org/Exporter.html

sub conectar{
    #definición de variables
    $BD = "blockbuster";
    $host = "localhost";
    $puerto = "3306";
    $tabla = "Peliculas";
    $user = "root";
    $pwd = "";

    # Declaras cadena de conexion
    $dsn = "dbi:mysql:$BD:$host:$puerto";

    # Abrimos la conexion
    $dbh = DBI->connect($dsn, $user, $pw)  or die "Error de conexión: $DBI::errstr\n";

    return $dbh;
}

And the error that marks me is the following:

edgargc@edgarHP:/var/www/html/Sistema/cgi-bin$ perl getAll.pl
Status: 500
Content-type: text/html

<h1>Software error:</h1>
<pre>Can't locate Conexiones.pm in @INC (you may need to install the Conexiones module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at getAll.pl line 8.
BEGIN failed--compilation aborted at getAll.pl line 8.
</pre>
<p>
For help, please send mail to this site's webmaster, giving this error message
and the time and date of the error.

</p>
[Wed Nov 28 23:25:45 2018] getAll.pl: Can't locate Conexiones.pm in @INC (you may need to install the Conexiones module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at getAll.pl line 8.
[Wed Nov 28 23:25:45 2018] getAll.pl: BEGIN failed--compilation aborted at getAll.pl line 8.

Can someone help me understand the reason why it fails?

    
asked by Edgar Gc 29.11.2018 в 06:29
source

1 answer

0

The error says that the main program is not able to find the position of the Connections library.pm

As it says in the error message itself, you must indicate a hint, or a path to that file.

In the main program, put a line at the beginning, before

use Connections;

make it

use lib "/ path / absolute / or / relative / to / the / folder / where / is / the / library";

    
answered by 29.11.2018 / 14:07
source