Front page | perl.beginners |
Postings from April 2012
Re: & and subroutine
Thread Previous
|
Thread Next
From:
Michael Rasmussen
Date:
April 17, 2012 05:51
Subject:
Re: & and subroutine
Message ID:
20120417125050.GB27297@jamhome.us
On Tue, Apr 17, 2012 at 02:30:59PM +0200, Manfred Lotz wrote:
> > Could someone please expand on this as I seem to always have to do
> > this. If I 'use strict' and 'use warnings' I get errors if I don't.
> >
>
> 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.
Alternatively, and to my sensibilities cleaner:
#!/usr/bin/perl
use strict;
use warnings;
sub mysub; # declares it, mysub no longer a bareword
mysub(); # does it, () not required for Perl parser, but are nice for maintainers
sub mysub { # defines it
print "Hi! Nice to see you!\n";
}
--
Michael Rasmussen, Portland Oregon
Other Adventures: http://www.jamhome.us/ or http://westy.saunter.us/
Fortune Cookie Fortune du courrier:
Whatever destiny your relationship has, a tandem will get you there faster.
Thread Previous
|
Thread Next