On Tuesday 17 April 2012 13:30:59 Manfred Lotz wrote:
>
> One example is this:
>
> #! /usr/bin/perl
>
> use strict;
> use warnings;
>
> mysub;
>
> sub mysub {
>   print "Hi there\n";
> }
>
> If you run this you get an error:
> Bareword "mysub" not allowed while "strict subs" in use at ./testsub.pl
> line 6. Execution of ./testsub.pl aborted due to compilation errors.
>
>
> Perl tells you that it has no idea what you mean when you use the
> bareword mysub.
>
>
> Now you have two options to solve it.
>
> 1. &mysub;
>
> Using the sigil & you tell Perl that mysub is a subroutine.
>
> 2. mysub();
>
> Usind () after mysub you also tell Perl that mysub is a subroutine.
>
>
> 3. &mysub();
>
> Combining 1. and 2. works also but is not recommended. Hmm, at least I
> do no recommend it.
>
>
> Use 2. and you'll be happy.
>
>
> There are surely some other situations where using & might be
> appropriate. But this one came into my mind immediately.
>Hi Manfred,

Thank you for this, but below is what I am meaning.

Gary

[root@stan ~]# cat t.pl 
#!/usr/bin/perl -w

use strict;
use warnings;


mysub();


sub mysub() {
  print "hello world\n";
}
[root@stan ~]# ./t.pl 
main::mysub() called too early to check prototype at ./t.pl line 7.
hello world

}

>
> --
> Manfred



-- 
Gary Stainburn
Group I.T. Manager
Ringways Garages
http://www.ringways.co.uk 

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to