I have come across a few Perl modules that for example look similar to the following code:
package MyPackage;
use strict;
use warnings;
use constant PERL510 => ( $] >= 5.0100 );
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw( );
{ #What is the significance of this curly brace?
my $somevar;
sub Somesub {
#Some code here
}
}
1;
What is the significance of 1; and of the curly braces that enclose the $somevar and the Sub?
1at the end of a module means that the module returnstruetouse/requirestatements. It can be used to tell if module initialization is successful. Otherwise,use/requirewill fail.$somevaris a variable which is accessable only inside the block. It is used to simulate “static” variables. Starting from Perl 5.10 you can use keywordstatekeyword to have the same results: