What does the word '&myvariable' mean?what does the symbol '&' means? What's purpose of it?

Showing Answers 1 - 3 of 3 Answers

maruthr

  • Apr 16th, 2008
 

  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.

  Was this answer useful?  Yes

nitashaa

  • Jul 15th, 2008
 

&myvariable;
It indicates 'myvariable' is a subroutine which is being called in the above statement .

Its mandatory to use & keyword before subroutine name only when userdefined subroutine name clashes with system defined subroutine .
Ex: sub open{
      print "file $_[0] is the file to openn";
    }

  &open('file1');

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.