Re: marine subroutine



2007/8/30, Amichai Teumim <amichai@xxxxxxxxxx>:
Hi

I'm trying to understand subroutines.

#!/usr/bin/perl

&marine()

sub marine {
$n += 1; #Global variable $n
print "Hello, sailor number $n!\n";
}


This doesn't work. Is &marine() incorrect? How would I call the sub marine?


Because you lost a ';' after &marine().

Also from perldoc perlsub,

To call subroutines:

NAME(LIST); # & is optional with parentheses.
NAME LIST; # Parentheses optional if predeclared/imported.
&NAME(LIST); # Circumvent prototypes.
&NAME; # Makes current @_ visible to called subroutine.
.



Relevant Pages

  • Re: marine subroutine
    ... On 30 Aug 2007 at 1:18, anders wrote: ... I'm trying to understand subroutines. ... print "Hello, sailor number $n!\n"; ... How would I call the sub marine? ...
    (perl.beginners)
  • Re: marine subroutine
    ... I'm trying to understand subroutines. ... print "Hello, sailor number $n!\n"; ... Is &marineincorrect? ... How would I call the sub marine? ...
    (perl.beginners)
  • marine subroutine
    ... I'm trying to understand subroutines. ... print "Hello, sailor number $n!\n"; ... Is &marineincorrect? ... How would I call the sub marine? ...
    (perl.beginners)