nntp2http.com
Posting
Suche
Optionen
Hilfe & Kontakt

use und Variablen

Von: Helmut Schneider (jumper99@gmx.de) [Profil]
Datum: 29.10.2009 12:23
Message-ID: <7ktc9eF3a6pvbU1@mid.individual.net>
Newsgroup: de.comp.lang.perl.misc
Hi,

# cat ./test.pl
#!/usr/bin/perl

use strict;
use warnings;

use lib "./";
our $myVarA = 1;
our $myVarB = 2;
use myTest;

print "\$myVarA = $main::myVarA\n";
print "\$myVarB = $main::myVarB\n";
# cat ./myTest.pm
package myTest;

print "\$myVarA = " . $main::myVarA . "\n";
print "\$myVarB = " . $main::myVarB . "\n";

1;
# perl ./test.pl
$myVarA
$myVarB
$myVarA = 1
$myVarB = 2
#

Soweit ich "use" verstanden habe, war das zu erwarten, da "use" vor
dem
Kompilieren stattfindet. Lösen liese sich das "Problem", indem man
"use" durch "require" ersetzt.
Nun lese ich aber überall, dass man "use" einem "require" wo
immer
möglich vorziehen soll. Ist obiges so eine Ausnahme, oder gibt es auch
einen "use"-Weg?

Ziel ist es, in einem package sicher zu stellen, dass bestimmte $main::
Variablen gesetzt wurden.

Danke und Gruß, Helmut

--
No Swen today, my love has gone away
My mailbox stands for lorn, a symbol of the dawn

[ Auf dieses Posting antworten ]

Antworten