1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#! /opt/bin/perl
use strict;
use lib "/export/home/scripts/NetAct";
use loginmodules::NAnorth;
login();
my $sth = $dbh->prepare("SELECT * FROM $values[5] WHERE rownum <11");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'BSCID'}, name = $ref->{'name'}\n";
}
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package NAnorth;
use DBI();
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK @values $dbh);
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = (login);
sub login {
my $loginfile = '/export/home/scripts/NetAct/logindata/nan_login.txt';
open (DAT, $loginfile);
our @values = split (';',<DAT>); #(0 ip, 1 port, 2 user, 3 sesam, 4 database, 5 table)
print Dumper(\@values); #Still debugging.....
our $dbh = DBI->connect("DBI:mysql:database=$values[4];host=$values[0]","$values[2]", "$values[3]",{'RaiseError' => 1});
print ("No Error? PERFECT, Database connected\n");
}
1;
1 2 3 4 5 6 7
use Foo; # Foo hat die Funktion bzw. Methode bar # $rv: Return-Value my $rv = Foo->bar; # ruft sub bar{} mit 'Foo' als erstes Argument my $rv = bar Foo; # same as above my $rv = Foo::bar; # kein Argument wird übergeben my $rv = Foo::bar(@args); # Übergabe @args my $rv = Foo->bar(@args); # Achtung, erstes Argument ist 'Foo', dann @args
QuoteUndefined subroutine &main::comein called at etperf.pl line 11.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#! /opt/bin/perl
use strict;
use warnings;
use lib "/export/home/scripts/NetAct";
use loginmodules::NAnorth qw(&comein @comeincredentials $dbh);
our ($dbh, @comeincredentials);
&comein();
#$dbh = loginmodules::NAnorth::comein($dbh); FUNKTIONIERT NICHT!
#@comeincredentials = loginmodules::NAnorth::comein(@comeincredentials); FUNKTIONIERT NICHT!
my $sth = $dbh->prepare("SELECT * FROM $comeincredentials[5] WHERE rownum <11");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'BSCID'}, name = $ref->{'name'}\n";
}
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package NAnorth;
use strict;
use warnings;
use DBI();
require Exporter;
our (@ISA, @EXPORT, @EXPORT_OK, @comeincredentials, $dbh);
@ISA = qw(Exporter);
@EXPORT_OK = qw(&comein @comeincredentials $dbh);
sub comein {
my $loginfile = '/export/home/scripts/NetAct/logindata/nan_login.txt';
open (DAT, $loginfile);
@comeincredentials = split (';',<DAT>); #(0 ip, 1 port, 2 user, 3 sesam, 4 database, 5 table)
print Dumper(\@comeincredentials); #Still debugging.....
$dbh = DBI->connect("DBI:mysql:database=$comeincredentials[4];host=$comeincredentials[0]","$comeincredentials[2]", "$comeincredentials[3]",{'RaiseError' => 1});
print ("No Error? PERFECT, Database connected\n");
}
1;
use loginmodules::NAnorth qw(&comein @comeincredentials $dbh);
1 2
require loginmodules::NAnorth; loginmodules::NAnorth->import( qw(&comein @comeincredentials $dbh) );
Quotech blicke mit der Variablendeklaration zwischen Modul und Skript irgendwie noch nicht ganz durch
perldoc perldebug
1
2
3
4
5
6
7
8
9
10
$dbh = DBI->connect("dbi:Oracle:", "user", 'sesam');
unless ( $dbh ) {
# Hier Code falls connect mißlungen
}
$csr0 = $dbh->prepare($Name_1._SQL_Statement);
$csr0->execute;
usw.