in reply to (Ovid) Re: is this correct?
in thread is this correct?
Compile time errors about barewords. Now move the sub definitions up:#!/usr/bin/perl -w use strict; fight; win; sub fight { print "Fighting!\n"; } sub win { print "Winning!\n"; }
Works fine. One more try:#!/usr/bin/perl -w use strict; sub fight { print "Fighting!\n"; } sub win { print "Winning!\n"; } fight; win;
There. While I definitely recommend putting the braces () on the end of any subroutine name for the sake of code clarity, if a bareword can be resolved to a known subroutine name, whether defined in your package or imported via use or require or eval, the compiler won't throw an error. That's probably more specific than anyone wants to know, though.#!/usr/bin/perl -w use strict; use subs qw ( fight win ); fight; win; sub fight { print "Fighting!\n"; } sub win { print "Winning!\n"; }
Update: Yes, because require and eval work at run-time (not compile time), they need to be in a BEGIN block. Sorry for being unclear.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Bare Subnames
by tilly (Archbishop) on Aug 10, 2000 at 15:33 UTC |