Thread Variable als subname: Subroutine funzt ned (7 answers)
Opened by dyspro at 2007-04-10 00:26

bloonix
 2007-04-10 00:45
#75771 #75771
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo dyspro,

[quote=dyspro,09.04.2007, 22:26]1 #!/usr/bin/perl
     2 use strict;
     3 use warnings;
     4 sub main {
     5      my $eingabe = readline<STDIN>;
     6      &$eingabe;
     7 }[/quote]
hier liegt ein grosses Missverständnis vor! :) $eingabe ist keine
Routine, sondern ein Skalar (im perlschen Kontext) und einen
Skalar spricht man mit einem Dollarzeichen an, deshalb kann
das auch nicht funktionieren. Ein UND-Zeichen ist für Routinen
gedacht, wie sie mit sub{} erzeugt werden. Erkennst du
deinen Fehler? Das kannst du auch nochmal zum besseren
Verständnis in Perldoc nachlesen.

perldata

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use strict;
use warnings;

sub main {
    my $eingabe = <STDIN>;
    &hello; # hello ist eine Routine
    print $eingabe, "\n"; # $eingabe ist ein Skalar
}

sub hello {
  print "hi ";
}

&main;


Gruss,
opi\n\n

<!--EDIT|opi|1176151622-->
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.

View full thread Variable als subname: Subroutine funzt ned