Fehlermeldung : PERL WARNING: "my" variable $result masks earlier declaration

Begonnen von Tho-Gra, 16 Januar 2016, 22:15:19

Vorheriges Thema - Nächstes Thema

Tho-Gra

Hallo alle zusammen,

Ich bin nicht wirklich Leistungsstark was PERL angeht.

Aber ich verstehe nicht was ich laut der Fehlermeldung falsch mache.
Könnt ihr mir vielleicht weiterhelfen?

Programmcode
##### Berechnung des Byte - Zusammengestellt aus den Bits###########
define Calc_Beckhoff_Main_In_0 notify Calc_Beckhoff_Main_In_0 {\
my $result = 0;;;;\
my $result=$result + 1 * Value("Beckhoff_Main_In_0_Bit_0");;;;\
my $result=$result + 2 * Value("Beckhoff_Main_In_0_Bit_1");;;;\
my $result=$result + 4 * Value("Beckhoff_Main_In_0_Bit_2");;;;\
my $result=$result + 8 * Value("Beckhoff_Main_In_0_Bit_3");;;;\
my $result=$result + 16 * Value("Beckhoff_Main_In_0_Bit_4");;;;\
my $result=$result + 32 * Value("Beckhoff_Main_In_0_Bit_5");;;;\
my $result=$result + 64 * Value("Beckhoff_Main_In_0_Bit_6");;;;\
my $result=$result + 128 * Value("Beckhoff_Main_In_0_Bit_7");;;;\
my $result=$result + 256 * Value("Beckhoff_Main_In_1_Bit_0");;;;\
my $result=$result + 512 * Value("Beckhoff_Main_In_1_Bit_1");;;;\
my $result=$result + 1024 * Value("Beckhoff_Main_In_1_Bit_2");;;;\
my $result=$result + 2048 * Value("Beckhoff_Main_In_1_Bit_3");;;;\
my $result=$result + 4096 * Value("Beckhoff_Main_In_1_Bit_4");;;;\
my $result=$result + 8192 * Value("Beckhoff_Main_In_1_Bit_5");;;;\
my $result=$result + 16384 * Value("Beckhoff_Main_In_1_Bit_6");;;;\
my $result=$result + 32768 * Value("Beckhoff_Main_In_1_Bit_7");;;;\
fhem("set Beckhoff_Main_In_0 $result");;;;\
}


Fehlermeldung
2016.01.16 22:07:04 1: PERL WARNING: "my" variable $result masks earlier declaration in same scope at (eval 105) line 4.
2016.01.16 22:07:04 3: eval: my $TYPE='notify';my $SELF='Calc_Beckhoff_Main_In_0';my $EVENT='';my $NAME='Calc_Beckhoff_Main_In_0';{
my $result = 0;;
my $result=$result + 1 * Value("Beckhoff_Main_In_0_Bit_0");;
my $result=$result + 2 * Value("Beckhoff_Main_In_0_Bit_1");;
my $result=$result + 4 * Value("Beckhoff_Main_In_0_Bit_2");;
my $result=$result + 8 * Value("Beckhoff_Main_In_0_Bit_3");;
my $result=$result + 16 * Value("Beckhoff_Main_In_0_Bit_4");;
my $result=$result + 32 * Value("Beckhoff_Main_In_0_Bit_5");;
my $result=$result + 64 * Value("Beckhoff_Main_In_0_Bit_6");;
my $result=$result + 128 * Value("Beckhoff_Main_In_0_Bit_7");;
my $result=$result + 256 * Value("Beckhoff_Main_In_1_Bit_0");;
my $result=$result + 512 * Value("Beckhoff_Main_In_1_Bit_1");;
my $result=$result + 1024 * Value("Beckhoff_Main_In_1_Bit_2");;
my $result=$result + 2048 * Value("Beckhoff_Main_In_1_Bit_3");;
my $result=$result + 4096 * Value("Beckhoff_Main_In_1_Bit_4");;
my $result=$result + 8192 * Value("Beckhoff_Main_In_1_Bit_5");;
my $result=$result + 16384 * Value("Beckhoff_Main_In_1_Bit_6");;
my $result=$result + 32768 * Value("Beckhoff_Main_In_1_Bit_7");;
fhem("set Beckhoff_Main_In_0 $result");;
}

betateilchen

Zitat von: Tho-Gra am 16 Januar 2016, 22:15:19
Aber ich verstehe nicht was ich laut der Fehlermeldung falsch mache.
Könnt ihr mir vielleicht weiterhelfen?

Das my vor $result darf nur ein einziges Mal vorkommen, und zwar in der Zeile, wo Du die 0 zuweist. Danach ist die Variable bereits definiert und Du kannst ihren Wert verändern.

Also in allen Folgezeilen das my entfernen und alles ist gut. Perl-Grundlagen :)
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!

Tho-Gra

Manchmal sieht man den Wald vor lauter Bäume nicht.

Vielen Dank für die schnelle Antwort.