Tuesday, April 15, 2008

Subroutines in Perl

There are three different formats to be used for calling the subroutines/methods,
"hello" is the subroutine name, say

1) &hello;
Subroutine definition can be made anywhere in the file.
& is to tell compiler that, hello is a subroutine.

2) hello();
Subroutine definition can be made anywhere in the file.
() is tell compiler that, hello is a subroutine.

3) hello;
Subroutine definitions should be made before invocation
If you have a subroutine definition after the invocation; at least you need to declare it with "sub hello;" before invocation.
here sub is tell compiler that, there would be a subroutine named hello anywhere in the file.

No comments: