That's rubbish,
You can call a sub before you create it as you say. At compile time the
entire code is done (bar some exceptions)
The issue here is drop the & unless you really know what it does

my($n);
marine();

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

 }

Works fine.
 

-----Original Message-----
From: anders [mailto:[EMAIL PROTECTED] 
Sent: 30 August 2007 09:18
To: beginners@perl.org
Subject: Re: marine subroutine

On 30 Aug, 09:39, [EMAIL PROTECTED] (Amichai Teumim) wrote:
> 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?
>
> Thanks
>
> Amichai

You can't use somting BEFORE you have created it try to call and call sub
with name and () and ;

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

marine();



--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/



This e-mail is from the PA Group.  For more information, see
www.thepagroup.com.

This e-mail may contain confidential information.  Only the addressee is
permitted to read, copy, distribute or otherwise use this email or any
attachments.  If you have received it in error, please contact the sender
immediately.  Any opinion expressed in this e-mail is personal to the sender
and may not reflect the opinion of the PA Group.

Any e-mail reply to this address may be subject to interception or
monitoring for operational reasons or for lawful business practices.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to