Schrift
[thread]8941[/thread]

arrays vergleichen (Seite 2)

Leser: 5


<< |< 1 2 3 >| >> 24 Einträge, 3 Seiten
pq
 2007-04-24 18:54
#76185 #76185
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
[quote=PerlProfi,24.04.2007, 16:40]Man sollte doch davon ausgehen können, dass $[ nicht verändert wird, oder ?
Ich jedenfalls schreibe immer 0 ist das irgendwie schlimm ?[/quote]
Quote
              As of release 5 of Perl, assignment to $[ is treated as a compiler directive, and
              cannot influence the behavior of any other file.  (That's why you can only assign
              compile-time constants to it.)  Its use is highly discouraged.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
pq
 2007-04-24 18:57
#76186 #76186
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
[quote=opi,24.04.2007, 16:50]Weiß man, wer dran rum fummelt?[/quote]
ja, weiss man. siehe meine letzte antwort.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
bloonix
 2007-04-24 19:41
#76187 #76187
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
@pq, okay, das ist natürlich gut zu wissen. Dann sollte man natürlich
immer $[ anstatt 0 verwenden oder man setzt $[ nach allen "use modules"\n\n

<!--EDIT|opi|1177429424-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
lichtkind
 2007-04-24 21:22
#76188 #76188
User since
2004-03-22
5701 Artikel
ModeratorIn + EditorIn
[Homepage]
user image
schon mal nach CPAN:Arayy::Utils gesehen?
Wiki:Tutorien in der Wiki, mein zeug:
kephra, baumhaus, garten, gezwitscher

Es beginnt immer mit einer Entscheidung.
pq
 2007-04-24 21:31
#76189 #76189
User since
2003-08-04
12209 Artikel
Admin1
[Homepage]
user image
[quote=opi,24.04.2007, 17:41]@pq, okay, das ist natürlich gut zu wissen. Dann sollte man natürlich
immer $[ anstatt 0 verwenden oder man setzt $[ nach allen "use modules"[/quote]
häh, wieso das denn?
du brauchst es eben *nicht*.
solange du weisst, dass du in der datei kein $[ gesetzt hast, brauchst
du dich nicht kümmern.
andere module *können* das $[ in deiner datei gar nicht verändern.
ich vermute, du hast den abschnitt aus der doku genau falschherum verstanden.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem
bloonix
 2007-04-25 01:17
#76190 #76190
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
wenn ein modul mit use eingebunden wird, in dem $[ verändert wird,
dann ist auch der gesamte code davon betroffen... so zumindest
meine tests
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
Taulmarill
 2007-04-25 12:49
#76191 #76191
User since
2004-02-19
1750 Artikel
BenutzerIn

user image
opi hat recht. Scheint daran zu liegen, dass use zur Compilezeit ausgeführt wird. Wenn ich das selbe Modul mit require importiere, hat es keine Auswirkungen auf das eigentliche Script. Auch ein local $[; im Modul verhindert die Beeinflussung. Alles in allem sehr unschön.
$_=unpack"B*",~pack"H*",$_ and y&1|0& |#&&print"$_\n"for@.=qw BFA2F7C39139F45F78
0A28104594444504400 0A2F107D54447DE7800 0A2110453444450500 73CF1045138445F4800 0
F3EF2044E3D17DE 8A08A0451412411 F3CF207DF41C79E 820A20451412414 83E93C4513D17D2B
bloonix
 2007-04-25 12:57
#76192 #76192
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Okay, da es im IRC noch Unklarheiten gab...

Vodoo.pm
Code: (dl )
1
2
3
package Vodoo;
$[ = 20;
1;


test1.pl
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use strict;
use warnings;
use lib '.';
use Vodoo;

$[ = 0;

my @arrays1 = qw(w a f g b c j g r l);
my @arrays2 = qw(0 1 r 5 6 a l w f b g);

for my $cur (@arrays1) {
  for (my $i=0; $i<=$#arrays2; $i++) {
     print "$i - $cur kommt an Stelle $i im 2. Array vor.\n" if ($cur eq $arrays2[$i]);
  }
}


#> ./test1.pl
7 - w kommt an Stelle 7 im 2. Array vor.
5 - a kommt an Stelle 5 im 2. Array vor.
8 - f kommt an Stelle 8 im 2. Array vor.
10 - g kommt an Stelle 10 im 2. Array vor.
9 - b kommt an Stelle 9 im 2. Array vor.
10 - g kommt an Stelle 10 im 2. Array vor.
2 - r kommt an Stelle 2 im 2. Array vor.
6 - l kommt an Stelle 6 im 2. Array vor.


Das schaut also soweit ok aus, da $[ mit 0 kompiliert wird. Wenn aber
"use Vodoo;" nach "$[ = 0" eingebunden wird, passiert folgendes:

test2.pl
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use strict;
use warnings;
use lib '.';

$[ = 0;

use Vodoo;

my @arrays1 = qw(w a f g b c j g r l);
my @arrays2 = qw(0 1 r 5 6 a l w f b g);

for my $cur (@arrays1) {
  for (my $i=0; $i<=$#arrays2; $i++) {
     print "$i - $cur kommt an Stelle $i im 2. Array vor.\n" if ($cur eq $arrays2[$i]);
  }
}


#> test2.pl
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
16 - w kommt an Stelle 16 im 2. Array vor.
27 - w kommt an Stelle 27 im 2. Array vor.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.
Use of uninitialized value in string eq at ./test.pl line 15.


Und so weiter und so weiter...

Hier wurde in Vodoo.pm $[ auf 20 gesetzt und die for-Schleife beginnt
fix mit 0. Wie verhält man sich also, wenn irgendjemand in einem Modul
$[ verändert? Sollte man dann lieber die Laufvariable mit $[ initialisieren
oder auf das Modul verzichten?

Gruss,
opi\n\n

<!--EDIT|opi|1177491469-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
Taulmarill
 2007-04-25 15:12
#76193 #76193
User since
2004-02-19
1750 Artikel
BenutzerIn

user image
Wenn jemand in seinem Modul $[ global setzt ohne dafür einen guten Grund zu haben, ist das IMHO ein Zeichen für einen Fehler oder einfach schlechtes Design und würde wohl von dem Gebrauch abraten. Generell sehe ich keinen Grund, $[ zu setzen. Aber wenn man aus welchem Grund auch immer $[ benutzen will, sollte man das doch bitte lokalisieren.
$_=unpack"B*",~pack"H*",$_ and y&1|0& |#&&print"$_\n"for@.=qw BFA2F7C39139F45F78
0A28104594444504400 0A2F107D54447DE7800 0A2110453444450500 73CF1045138445F4800 0
F3EF2044E3D17DE 8A08A0451412411 F3CF207DF41C79E 820A20451412414 83E93C4513D17D2B
bloonix
 2007-04-25 15:30
#76194 #76194
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
[quote=Taulmarill,25.04.2007, 13:12]sollte man das doch bitte lokalisieren.[/quote]
meine rede\n\n

<!--EDIT|opi|1177500646-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.
<< |< 1 2 3 >| >> 24 Einträge, 3 Seiten



View all threads created 2007-04-24 16:21.