Howto syntax check perl
Posted: Tue Apr 23, 2013 2:00 pm
I want to syntax check my perl kildclient code. When I run 'perl x.pl' I get loads of $world errors; as its not defined. Any suggestions on a better approach?
Shedding a bit of light on this, I can now now use strict and use warnings as well as compile code from the command line by declaring $window as a global. kildclient puts $world in the main package scope, but use strict complains unless it is declared as extant.
The following seems to work
use strict;
use warnings;
our $world;
$world->send('hello');
I wanted to see what symbols were obviously declared, the following shows the ones in the main package and the Window package...
sub showDefinedSymbolsWorld
{
print "\nSymbols in World\n";
foreach my $entry (sort keys %World:: )
{
print "$entry\n";
}
print "\n";
}
sub showDefinedSymbols
{
print "\nSymbols in ".PACKAGE."\n";
foreach my $entry (sort keys %main:: )
{
print "$entry\n";
}
print "\n";
}
showDefinedSymbols();
showDefinedSymbolsWorld();
The following will load my init.pl which is the code kildclient loads
use strict;
use lib ".";
require "world.pm";
package main;
our $world = main::new();
eval require "init.pl";
I placed stub code for all the kildclient perl World routines I use in world.pm eg
use strict;
package world;
$::world is another way of writing $main::world
package main;
usage
use world;
my $world = world->new();
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
use Exporter;
$VERSION = 1.0;
@ISA = qw(Exporter);
@EXPORT = qw(
&trigger
&gettimernumber
&timer
&enatimer
&distimer
&send
&echonl
&connect
&disconnect
&loadplugin
);
@EXPORT_OK = qw();
%EXPORT_TAGS = ();
sub new {
my $class = shift;
my $self = {};
bless($self, $class);
return $self;
}
sub loadplugin
{
}
sub trigger
{
}
sub gettriggernumber
{
}
sub deltrigger
{
}
sub gettimernumber
{
}
sub timer
{
}
sub enatimer
{
}
sub distimer
{
}
1;
Shedding a bit of light on this, I can now now use strict and use warnings as well as compile code from the command line by declaring $window as a global. kildclient puts $world in the main package scope, but use strict complains unless it is declared as extant.
The following seems to work
use strict;
use warnings;
our $world;
$world->send('hello');
I wanted to see what symbols were obviously declared, the following shows the ones in the main package and the Window package...
sub showDefinedSymbolsWorld
{
print "\nSymbols in World\n";
foreach my $entry (sort keys %World:: )
{
print "$entry\n";
}
print "\n";
}
sub showDefinedSymbols
{
print "\nSymbols in ".PACKAGE."\n";
foreach my $entry (sort keys %main:: )
{
print "$entry\n";
}
print "\n";
}
showDefinedSymbols();
showDefinedSymbolsWorld();
The following will load my init.pl which is the code kildclient loads
use strict;
use lib ".";
require "world.pm";
package main;
our $world = main::new();
eval require "init.pl";
I placed stub code for all the kildclient perl World routines I use in world.pm eg
use strict;
package world;
$::world is another way of writing $main::world
package main;
usage
use world;
my $world = world->new();
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
use Exporter;
$VERSION = 1.0;
@ISA = qw(Exporter);
@EXPORT = qw(
&trigger
&gettimernumber
&timer
&enatimer
&distimer
&send
&echonl
&connect
&disconnect
&loadplugin
);
@EXPORT_OK = qw();
%EXPORT_TAGS = ();
sub new {
my $class = shift;
my $self = {};
bless($self, $class);
return $self;
}
sub loadplugin
{
}
sub trigger
{
}
sub gettriggernumber
{
}
sub deltrigger
{
}
sub gettimernumber
{
}
sub timer
{
}
sub enatimer
{
}
sub distimer
{
}
1;