Thread Was bedeutet das "-" ? (19 answers)
Opened by hlubenow at 2009-02-22 22:54

LanX-
 2009-02-23 03:18
#119074 #119074
User since
2008-07-15
1000 Artikel
BenutzerIn

user image
Hat mir keine Ruhe gelassen und es mal getestet, das Minus ist Namensbestandteil des Hashkeys und kein Syntaktisches Element.

da hab ich wohl was durcheinandergebracht ...

aus ProPerl/properl2-5.html
Code: (dl )
1
2
3
4
We can also write the subroutine so that it accepts both named parameters and a simple list. One
common technique borrowed from UNIX command line switches is to prefix named arguments with a
minus, to distinguish them from unnamed arguments. To determine how the subroutine has been called,
we just check the first character of the first parameter to see if it is a minus:



habs mal getestet, das Minus ist Namensbestandteil des Hashkeys und kein syntaktisches Element. Der Sinn dahinter ist es subs schreiben zu können die wahlweise positionale Parameter oder benannte Parameter haben. Dann kann man beim durchsuchen der Parameterliste diejenigen Parameter die mit "-" Anfangen als Hashkeys interpretieren.

In PBP wird dies übrigens abgelehnt, will man benannte Parameter übergeben und mischen, solle man lieber gleich eine Hashreferenz Literal erzeugen, also:

Code (perl): (dl )
subname ( {key1=>"value1", ...}, pos1, pos2,...)


Und ich hab jetzt auch die Quelle meiner Verwirrung lokalisiert! CGI.pm!

Code: (dl )
1
2
3
4
5
       Each argument name is preceded by a dash.  Neither case nor order mat‐
ters in the argument list. -type, -Type, and -TYPE are all acceptable.
In fact, only the first argument needs to begin with a dash. If a dash
is present in the first argument, CGI.pm assumes dashes for the subse‐
quent ones.
CGI

bleibt die Frage ob Perl/Tk positionale und benannte Parameter mischt. Wohl,oder?


---
//Modedit Gwendragon: Link repariert
---

View full thread Was bedeutet das "-" ?