Schrift
[thread]7279[/thread]

Globale Variable in BEGIN Block setzen: Interaktion von my, our, undef und BEGIN (Seite 2)



<< |< 1 2 3 >| >> 26 Einträge, 3 Seiten
esskar
 2005-09-15 16:03
#58035 #58035
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
ich habe: This is perl, v5.8.7 built for MSWin32-x86-multi-thread
und mein ergebnis ist auch eine 1.
format_c
 2005-09-15 16:12
#58036 #58036
User since
2003-08-04
1706 Artikel
HausmeisterIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
M01169@pc851102:perldoc $ perl -v

This is perl, v5.8.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2002, Larry Wall

Binary build 804 provided by ActiveState Corp. http://www.ActiveState.com
Built 23:15:13 Dec 1 2002


Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

M01169@pc851102:perldoc $


Gruß Alex
Gast Gast
 2005-09-15 16:22
#58037 #58037
Ich bekomme »Use of uninitialized value in concatenation (.) or string at - line 5.« unter v5.8.3
pKai
 2005-09-15 16:50
#58038 #58038
User since
2005-02-18
357 Artikel
BenutzerIn
[default_avatar]
Code: (dl )
This is perl, v5.8.6 built for MSWin32-x86-multi-thread

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
>perl
use strict;
use warnings;
my $stuff = undef;
BEGIN { $stuff = 1; }
print "$stuff\n";
^Z
1

>perl -MO=Deparse
use strict;
use warnings;
my $stuff = undef;
BEGIN { $stuff = 1; }
print "$stuff\n";
^Z
use warnings;
use strict 'refs';
my $stuff;
sub BEGIN {
$stuff = 1;
}
print "$stuff\n";
- syntax OK

>perl
use strict;
use warnings;
my $stuff;
BEGIN { $stuff = 1; }
print "$stuff\n";
^Z
1

Die Leute mit der uninitialized-Warnung sollten mal die Variante mit der Variablendeklaration ohne Initialisierung (letzter perl-Aufruf, oder die Deparse-Ausgabe) laufen lassen. Meine Vermutung wäre, dass die ohne Mucken läuft.
I sense a soul in search of answers.
renee
 2005-09-15 17:05
#58039 #58039
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Trotzdem ist das etwas unlogisch, dass die Zuweisung weg"optimiert" wird. Kann ja sein, dass Du im BEGIN-Block was machst und das durch das = undef wieder rückgängig machen willst...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
esskar
 2005-09-15 17:10
#58040 #58040
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
warum eigentlich nicht?`
Code: (dl )
my $uhu;
und
Code: (dl )
my $uhu = undef;
sind ja vollkommen äquivalent.
murphy
 2005-09-15 17:23
#58041 #58041
User since
2004-07-19
1776 Artikel
HausmeisterIn
[Homepage]
user image
In diesem Kontext sollten sie eben nicht äquivalent sein!
When C++ is your hammer, every problem looks like your thumb.
Gast Gast
 2005-09-15 17:25
#58042 #58042
[quote=esskar,15.09.2005, 15:10]warum eigentlich nicht?`
Code: (dl )
my $uhu;
und
Code: (dl )
my $uhu = undef;
sind ja vollkommen äquivalent.[/quote]
Nicht auf 5.8.1 (das hatte ich gerade offen):
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
timon:/proj/work/rs/projects/runproc # perl
use strict;
use warnings;
my $stuff;
BEGIN { $stuff = 1; }
print "$stuff\n";
1
timon:/proj/work/rs/projects/runproc # perl
use strict;
use warnings;
my $stuff = undef;
BEGIN { $stuff = 1; }
print "$stuff\n";
Use of uninitialized value in concatenation (.) or string at - line 5.

timon:/proj/work/rs/projects/runproc #
Crian
 2005-09-20 19:49
#58043 #58043
User since
2003-08-04
5873 Artikel
ModeratorIn
[Homepage]
user image
nein, das ist doch aber auch klar.

Das zerfällt in zwei Teile: Deklaration "my $stuff" und Wertzuweisung "$stuff = undef". Zwischen diese wird per BEGIN-Block eine weitere Wertzuweisung geschoben. Wäre diese nicht im BEGIN-Block, so hätte die Variable den Wert 1, dadurch dass die Wertzuweisung im BEGIN-Block stattfindet, wird die Wertzuweisung im sonstigen Hauptteil eben danach ausgeführt und überschreibt den Wert.

s/Werrt/Wert/\n\n

<!--EDIT|Crian|1127303789-->
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite
Gast Gast
 2005-09-20 20:08
#58044 #58044
1:0 für Dich.
<< |< 1 2 3 >| >> 26 Einträge, 3 Seiten



View all threads created 2005-09-15 04:25.