![]() |
|< 1 ... 3 4 5 6 7 8 >| | ![]() |
72 Einträge, 8 Seiten |
QuoteErgo:
Zum Ausführungszeitpunkt des BEGIN Blocks sind dem Compiler (und damit dem Block) die Inhalte des Hauptprogramms (noch) nicht bekannt, daher ist es dem Block nicht möglich, auf Variablen des Hauptprogramms zuzugreifen
Quote- Variablen die innerhalb des BEGIN Blocks mit 'my' deklariert sind, werden vom Hauptprogramm 'nicht' gesehen
Quote- Variablen die innerhalb des BEGIN Blocks mit 'our' deklariert sind, werden vom Hauptprogramm gesehen
Quote- Variablen die innerhalb des BEGIN Blocks nicht deklariert werden, sind automatisch 'global' und werden vom Hauptprogramm gesehen
1
2
3
4
5
6
7
8
9
10
tina@tuxedo:~> perl -wle'
my $x; # lexikalisch
BEGIN {
$x = 23;
$y = 42;
}
print "x: $main::x, y: $main::y"'
Name "main::x" used only once: possible typo at -e line 7.
Use of uninitialized value in concatenation (.) or string at -e line 7.
x: , y: 42
QuoteDie Beispiele von ptk und pq sollte man einmal unter 'use strict' laufen lassen - dann wird der dortige Gedankenfehler klarer ...
1
2
3
4
5
6
7
8
tina@tuxedo:~> perl -Mstrict -wle'
my $x;
BEGIN {
$x = 1234;
}
warn $x;'
1234 at -e line 6.
tina@tuxedo:~>
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl
use strict;
use warnings;
my $xxx = 1234;
BEGIN {
warn $xxx;
$xxx = 5678;
warn $xxx;
}
warn $xxx;
1
2
3
4
Use of uninitialized value in warn at C:\Daten\perl\BEGIN.pl line 8.
Warning: something's wrong at C:\Daten\perl\BEGIN.pl line 8.
5678 at C:\Daten\perl\BEGIN.pl line 10.
1234 at C:\Daten\perl\BEGIN.pl line 13.
1
2
3
1234 at C:\Daten\perl\BEGIN2.pl line 8.
5678 at C:\Daten\perl\BEGIN2.pl line 10.
5678 at C:\Daten\perl\BEGIN2.pl line 13.
![]() |
|< 1 ... 3 4 5 6 7 8 >| | ![]() |
72 Einträge, 8 Seiten |