Your image shows that all of your scripts start with !#/usr/bin/perl
. This is wrong. It is not a valid she-bang line, it is read as negation !
followed by a comment #
. The parsing will continue and with script1.pl perl will execute ! print "Hello world.\n";
. This will print Hello world
and negate the result of print
... not really useful, but valid perl.
In script2.pl perl sees ! use strict;
and this is a compile time error and therefor perl fails and reports the error for the line use strict;
.
So if you use correct she-bang lines, all three scripts will work as designed.
Edit (test scripts added):
script1.pl
!#/usr/bin/perl
print "Hello world.\n" ;
Calling perl script1.pl
gives
Hello world.
script2.pl
!#/usr/bin/perl
use strict;
use warnings ;
print "Hello world.\n" ;
Calling perl script2.pl
gives
"use" not allowed in expression at script2.pl line 3, at end of line
syntax error at script2.pl line 3, near "use strict "
BEGIN not safe after errors--compilation aborted at script2.pl line 4.
Using the correct syntax script3.pl
#!/usr/bin/perl
use strict ;
use warnings ;
print "Hello world.\n" ;
Calling perl script3.pl
gives
Hello world.