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;
Howto syntax check perl
Re: Howto syntax check perl
Try this:
...which produces the output:
There's still a complaint about main::world, but at least you can see that there are no errors. (If there are errors, they appear first, before the complain about main::world.)
Code: Select all
perl -cw test.pl
Code: Select all
Name "main::world" used only once: possible typo at test.pl line 16 (#1)
(W once) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention it
again somehow to suppress the message. The our declaration is
provided for this purpose.
NOTE: This warning detects symbols that have been used only once so $c, @c,
%c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered
the same; if a program uses $c only once but also uses any of the others it
will not trigger this warning.
test.pl syntax OK