The use strict consists of 3 parts. One of them (use strict "subs") is responsible for prohibiting the indiscriminate of the naked word .
What does that mean?
Without this restriction, the following code can also print "Hello".
My $x = hello;print "$x \ n"; # Hello
This use does not conform to the usual habit of putting strings in quotation marks, but Perl defaults to allowing (using) the bare word --the word without quotation marks--as a string.
The above code outputs "Hello".
Of course, at least before the "Hello" function is added by default at the top of the script (this is the case):
Sub Hello { return "zzz";} My $x = hello;print "$x \ n"; # ZZZ
In the new version, Perl sees the Hello () function, calls it (function), and assigns the result to $x.
Then, if someone puts this function at the end of the file (after assignment), Perl does not see the function at the time of assignment, and it returns to the old: "Hello" is assigned to $x.
Yes, you certainly don't want to get yourself into trouble. So avoid confusion by using use strict in your code to prevent the naked word hello from appearing in your code.
Use strict;my $x = hello;print "$x \ n";
The following error is given:
Bareword "Hello" not allowed while "strict subs" in use with script.pl line 3.Execution of script.pl aborted due to Compilat Ion errors.
Correct use of the bare word
Even if the use strict "subs" is turned on, there are some places where you can have a bare word.
First, the user-defined function name is the bare word.
Similarly, in the Extract hash Table element curly braces also use the naked word, as well as the fat arrow = left can also be without quotation marks.
Use strict;use warnings;my%h = (name = ' Foo ');p rint $h {name}, "\ n";
The "name" in the code above is a bare word, which is also valid when use strict.
Naked words to learn in Perl