Schrift
[thread]6341[/thread]

abgedrehtes problem mit switch: oder bin ich blind? (Seite 4)



<< |< 1 2 3 4 5 6 7 8 >| >> 72 Einträge, 8 Seiten
Gast Gast
 2004-07-03 14:32
#83460 #83460
[quote=sri,03.07.2004, 04:05][quote=Dieter,03.07.2004, 01:57][quote=steffenw,02.07.2004, 22:10]Was man in einen BEGIN-Block schreibt, was macht mod_perl dann, nur einmal oder immer wieder?[/quote]
BEGIN { }
ist nichts anderes als eine ganz normale Subroutine.
Der Block wird also nicht anders compiliert als jeder andere Teil des Scripts auch.[/quote]
Ich werde das jetzt nicht korrigieren, aber fairneshalber gebe ich dir einen Hinweis. "perldoc perlmod"[/quote]
A "BEGIN" subroutine is executed as soon as possible, that is, the
moment it is completely defined, even before the rest of the containing
file is parsed. You may have multiple "BEGIN" blocks within a file--they
will execute in order of definition. Because a "BEGIN" block executes
immediately, it can pull in definitions of subroutines and such from
other files in time to be visible to the rest of the file. Once a
"BEGIN" has run, it is immediately undefined and any code it used is
returned to Perl's memory pool. This means you can't ever explicitly
call a "BEGIN".
renee
 2004-07-03 18:46
#83461 #83461
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Naja, eine ganz normale Subroutine ist es ja nicht...

* Man kann es nicht explizit aufrufen,
* Wenn es ausgeführt wurde ist es undef,
* wird so früh wie möglich ausgeführt
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/
sri
 2004-07-03 20:13
#83462 #83462
User since
2004-01-29
828 Artikel
BenutzerIn
[Homepage] [default_avatar]
[quote=Dieter,03.07.2004, 12:32]
A "BEGIN" subroutine is executed as soon as possible, that is, the
moment it is completely defined, even before the rest of the containing
file is parsed. You may have multiple "BEGIN" blocks within a file--they
will execute in order of definition. Because a "BEGIN" block executes
immediately, it can pull in definitions of subroutines and such from
other files in time to be visible to the rest of the file. Once a
"BEGIN" has run, it is immediately undefined and any code it used is
returned to Perl's memory pool. This means you can't ever explicitly
call a "BEGIN".[/quote]
Bitte aktuelle doku benutzen!!!

Quote
A "BEGIN" code block is executed as soon as possible, that is, the moment it is completely defined, even before the rest of the containing file (or string) is parsed...

...These code blocks can be prefixed with "sub" to give the appearance of a subroutine (although this is not considered good style). One should note that these code blocks don't really exist as named subroutines (despite their appearance). The thing that gives this away is the fact that you can have more than one of these code blocks in a program, and they will get all executed at the appropriate moment. So you can't execute any of these code blocks by name....

...It should be noted that "BEGIN" code blocks are executed inside string "eval()"'s...
\n\n

<!--EDIT|sri|1088871271-->
Gast Gast
 2004-07-03 20:37
#83463 #83463
[quote=renee,03.07.2004, 16:46]Naja, eine ganz normale Subroutine ist es ja nicht...

* Man kann es nicht explizit aufrufen,
* Wenn es ausgeführt wurde ist es undef,
* wird so früh wie möglich ausgeführt[/quote]
Das ist schon richtig - aber irgendwie sollte herübergekommen sein dass 'auch' ein BEGIN-Block, zunächst einmal compiliert und dann erst ausgeführt wird.
Ob es sich bei BEGIN, END usw. um jeweils einen Code-Block oder um eine Subroutine (die ja irgendwo auch ein Code-Block ist) handelt, ist schlichte Haarspalterei.
sri
 2004-07-03 21:03
#83464 #83464
User since
2004-01-29
828 Artikel
BenutzerIn
[Homepage] [default_avatar]
[quote=Dieter,03.07.2004, 18:37]Ob es sich bei BEGIN, END usw. um jeweils einen Code-Block oder um eine Subroutine (die ja irgendwo auch ein Code-Block ist) handelt, ist schlichte Haarspalterei.[/quote]
Eben nicht, BEGIN Blöcke sind etwas ganz anderes. (können mehrfach vorkommen, werden zur compile time ausgeführt, werden in string eval() ausgeführt etc.)

Eine constante ist auch irgendwie eine variable.</sarkasmus> ;)
Crian
 2004-07-05 14:10
#83465 #83465
User since
2003-08-04
5873 Artikel
ModeratorIn
[Homepage]
user image
Zum Beispiel kannst Du in BEGIN Blöcken auch nicht auf globale Variablen zugreifen, die im normalen "nicht-BEGIN" Teil definiert werden, eben weil diese Blöcke vorher compiliert und ausgeführt werden.

(Übrigens ist es klar, dass die erst kompiliert bzw. interpretiert und dann ausgeführt werden, anders geht ja wohl schlecht.)


Ich würde sagen, ein BEGIN-Block ist keine Subroutine. Die Unterschiede sind mir doch zu groß =)
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
 2004-07-05 16:11
#83466 #83466
[quote=Crian,05.07.2004, 12:10]Zum Beispiel kannst Du in BEGIN Blöcken auch nicht auf globale Variablen zugreifen, die im normalen "nicht-BEGIN" Teil definiert werden, eben weil diese Blöcke vorher compiliert und ausgeführt werden.

(Übrigens ist es klar, dass die erst kompiliert bzw. interpretiert und dann ausgeführt werden, anders geht ja wohl schlecht.)


Ich würde sagen, ein BEGIN-Block ist keine Subroutine. Die Unterschiede sind mir doch zu groß =)[/quote]
Es steht außer Frage das aus einem BEGIN Block heraus die Varibalen des Hauptprogramms nicht erreichbar sind - daher der Name BEGIN.
Demgegenüber kannst Du mit einem END Block auf persistente (auch globale) Variablen zugreifen und aus einem END Block heraus, immer noch Funktionen des Hauptrogramms aufrufen.

Der END Block bietet also u.a. die interessante Möglichkeit, Funktionen im Hintergrund ablaufen zu lassen während bereits eine neue (unabhängige) Instanz des Hauptprogramms (ein neuer/zusätzlicher Prozess) gestartet worden ist.
sri
 2004-07-05 16:30
#83467 #83467
User since
2004-01-29
828 Artikel
BenutzerIn
[Homepage] [default_avatar]
Deine Beispiele sind ja ok, mal abgesehen davon das persistenz was anderes ist, aber ich habe leider mal wieder absolut keine Ahnung was du uns damit eigendlich sagen wolltest?

P.S.: Ohne dich in irgendeiner Form beleidigen, angreifen, verunglimpfen, provozieren, deprimieren, oder lächerlich machen zu wollen... ;)
Taulmarill
 2004-07-05 16:32
#83468 #83468
User since
2004-02-19
1750 Artikel
BenutzerIn

user image
die unterschiede zwischen normalen sub's und BEGIN, INIT, CHECK und END blöcken sind unter folgendem link detailiert nachzulesen

http://www.perldoc.com/perl5.8....and-END

oder einfach perldoc perlmod :D
$_=unpack"B*",~pack"H*",$_ and y&1|0& |#&&print"$_\n"for@.=qw BFA2F7C39139F45F78
0A28104594444504400 0A2F107D54447DE7800 0A2110453444450500 73CF1045138445F4800 0
F3EF2044E3D17DE 8A08A0451412411 F3CF207DF41C79E 820A20451412414 83E93C4513D17D2B
Gast Gast
 2004-07-05 16:43
#83469 #83469
[quote=sri,05.07.2004, 14:30]Deine Beispiele sind ja ok, mal abgesehen davon das persistenz was anderes ist[/quote]
Dann kläre mich doch bitte auf - was ist Persistenz?
<< |< 1 2 3 4 5 6 7 8 >| >> 72 Einträge, 8 Seiten



View all threads created 2004-06-16 21:56.