Why do the subs execute?  Because you told them to.  When you type
funca(), you're telling Perl to execute funca, but don't pass it any
parameters.  You don't "declare" subs in Perl the way you would in C.
The only place you declare a sub is in the "sub mySub{BLOCK}" statement.
You CAN prototype a subroutine to check variable types that are passed
to a sub, but that's a different story.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 04, 2003 10:59 AM
To: [EMAIL PROTECTED]
Subject: ref's to subs


Hello Perler's

I am trying to create a hash where each key is a referance to subs. The
bellow code produces the expected result, with one unexpected
side-effect. Why are the subs executed when I only declare them ??

<- cut
 #!/usr/local/bin/perl -w


%hash=( 1 => funca(),
        2 => funcb(),
      );




sub funca{

        print "a";
}

sub funcb{

        print "b";
}

<- paste
Thanks in Advance,
Mark G


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to