Thread Datenbankzugriffe in Subroutinen (3 answers)
Opened by panni at 2015-07-29 09:36

Raubtier
 2015-07-29 12:10
#181684 #181684
User since
2012-05-04
1054 Artikel
BenutzerIn

user image
Das &-Zeichen verändert den Funktionsaufruf, indem es erstens Prototypen ignoriert und zweitens übergibt es dir beim Aufruf ohne Klammern @_. Das sind beides Dinge, die man normalerweise nicht will.

Daher: benutze kein & im Normalfall. Benutze &, wenn du weißt, warum du es gerade brauchst.

Vergleiche z.B.
Code: (dl )
1
2
3
4
perl -E'sub x(\$){}; x("hallo")' 
Type of arg 1 to main::x must be scalar (not constant item) at -e line 1, near ""hallo")
"
Execution of -e aborted due to compilation errors.

vs.
Code: (dl )
perl -E'sub x(\$){}; &x("hallo")'


Und hier:
Code: (dl )
perl -wE'sub x{say for @_}; @_=qw(1 2); x; '

vs.
Code: (dl )
1
2
3
perl -wE'sub x{say for @_}; @_=qw(1 2); &x; '
1
2

View full thread Datenbankzugriffe in Subroutinen