strict “subs”
This stricture makes Perl treat all barewords as syntax errors. A bareword (“bearword” in ursine dialects) is any bare name or identifier that has no other interpretation forced by context. (Context is often forced by a nearby keyword or token, or by predeclaration of the word in question.) Historically, barewords were interpreted as unquoted strings. This stricture outlaws that interpretation. If you mean to use it as a string, quote it. If you mean to use it as a function call, predeclare it or use parentheses.
As a particular case of forced context, remember that a bareword
that appears by itself in curly braces or on the lefthand side of the
=> operator counts as being
quoted, and so is not subject to this restriction.
use strict "subs";
$x = whatever; # WRONG: bareword error!
$x = whatever(); # This always works, though.
sub whatever; # Predeclare function.
$x = whatever; # Now it's ok.
# These uses are permitted, because the => quotes:
%hash = (red => 1, blue => 2, green => 3);
$rednum = $hash{red}; # Ok, braces quote here
# But not this one:
@coolnums = @hash{blue, green}; # WRONG: bareword error
@coolnums = @hash{"blue", "green"}; # Ok, words now quoted
@coolnums = @hash{qw/blue green/}; # LikewiseBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access