This question may be stupid. But I just started exploring Perl. I am using Perl v5.16.2. I know that the say
statement has been introduced in 5.10.
#!/usr/bin/perl
say "Hello World!";
When I try to run above program, I am getting the following error:
$ ./helloPerl
String found where operator expected at ./helloPerl line 3, near "say "Hello World!""
(Do you need to predeclare say?)
syntax error at ./helloPerl line 3, near "say "Hello World!""
Execution of ./helloPerl aborted due to compilation errors.
But when I added the statement use 5.016;
, it is giving me the correct output.
#!/usr/bin/perl
use 5.016;
say "Hello World!";
My doubt is, I am using perl v5.16.2, which is above 5.010. Why should I mention the Perl version using a use
statement here?
The IF statement is a decision-making statement that guides a program to make decisions based on specified criteria. The IF statement executes one set of code if a specified condition is met (TRUE) or another set of code evaluates to FALSE.
Statements are used in JavaScript to control its program flow. Unlike properties, methods, and events, which are fundamentally tied to the object that owns them, statements are designed to work independently of any JavaScript object.
A return statement ends the execution of a function, and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.
When you combine each one of them with an IF statement, they read like this: AND – =IF(AND(Something is True, Something else is True), Value if True, Value if False) OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False)
Features that might break backwards compatibility, aren't enabled by default.
See perldoc feature
:
It is usually impossible to add new syntax to Perl without breaking some existing programs. This pragma provides a way to minimize that risk. New syntactic constructs, or new semantic meanings to older constructs, can be enabled by use feature 'foo' , and will be parsed only when the appropriate feature pragma is in scope. (Nevertheless, the CORE:: prefix provides access to all Perl keywords, regardless of this pragma.)
use
on a version number, implicitly enables all features, because it also applies a constraint on perl version. So you won't be tripped over by say
not being implemented, for example.
say
is a feature, it's not (yet - will it ever be?) regular perl syntax.
Use either
use feature qw(say);
or
use v5.010; # or any version later
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With