Error when using a defining a new module

A

ashwani

Hi
i am writting a new module service_ini.
here is the code which is using the module:
#!/usr/bin/perl

#use strict;
use warnings;

BEGIN {
push @INC, 'D:/Strech Goals/Unit test Automation/Development/
service_ini/lib';
}
use service_ini;


my %this = (SERVICE_INI_FILE_NAME => "sgutat.ini");
$this{'TRACE_FILE_NAME'} = "D:/Strech Goals/Unit test Automation/
Development/input files/OC_CC_C2_002.tra";

$this->{'SERVICE_INI_FD'} = service_ini::eek:penServiceIni();
$this->{'SERVICE_INI_PARAM'} = service_ini::ReadServiceINIParam($this-
{'SERVICE_INI_FD'});

open(TraFD,$this->{'TRACE_FILE_NAME'}) || die "Can't open file $this-
{'TRACE_FILE_NAME'}" ;
print "\n$this->{'TRACE_FILE_NAME'} has opened";
while(my $line = <TraFD>)
{
chomp($line);
if ($line =~ m/(State)(\[[0-9]+\]) ([0-9]+), SIB:((\w+\/\w+)((\/\w
+)*))/)
{
print "\nLine = $line";
print "\nState No: $3";
print "\nSIB Name: $4\n";


}
}#end of while
print "\nclosing $this->{'TRACE_FILE_NAME'}";
close(TraFD)|| die "Can't close file: $this->{'TRACE_FILE_NAME'}";





and code of service_ini module is
______________________________________________________
package service_ini;


#require Exporter;
#use AutoLoader qw(AUTOLOAD);

#our @ISA = qw(Exporter);

# Items to export into callers namespace by default. Note: do not
export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

# This allows declaration use service_ini ':all';
# If you do not need this, moving things directly into @EXPORT or
@EXPORT_OK
# will save memory.
#our %EXPORT_TAGS = ( 'all' => [ qw(

#) ] );

#our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

#our @EXPORT = qw(

#);

#our $VERSION = '0.01';


# Preloaded methods go here.

# Autoload methods go after =cut, and are processed by the autosplit
program.

#1;
#__END__
# Below is stub documentation for your module. You'd better edit it!

=head1 NAME

service_ini - Perl extension for blah blah blah

=head1 SYNOPSIS

use service_ini;
blah blah blah

=head1 DESCRIPTION

Stub documentation for service_ini, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.

Blah blah blah.

=head2 EXPORT

None by default.



=head1 SEE ALSO

Mention other useful documentation such as the documentation of
related modules or operating system documentation (such as man pages
in UNIX), or any relevant external documentation such as RFCs or
standards.

If you have a mailing list set up for your module, mention it here.

If you have a web site set up for your module, mention it here.

=head1 AUTHOR

A. U. Thor, E<lt>[email protected]<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2007 by A. U. Thor

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.


=cut


use 5.008006;
use strict;
use warnings;

my $service_ini_file_name = 'sgutat.ini'

#sub new {

#return $this;
#}
sub openServiceIni {
print "\nEntry in service_ini::eek:penServiceIn";
my $FD=undef;
open($FD,$service_ini_file_name) || die "\ncan not open
configuration file $service_ini_file_name\n";
print "\nExit from service_ini::eek:penServiceIni";
return $FD;
}
sub ReadServiceINIParam
{
print "\nEntry in service_ini::ReadServiceINIParam";
#my $FH = undef;
#open($FH,$service_ini_file_name) || die "\ncan not open
configuration file $service_ini_file_name\n";


print "\nExit from service_ini::ReadServiceINIParam";
}#end of ReadServiceINIParam
1;


______________________________________________________


but when i am compiling this it is giving error as
syntax error at D:/Strech Goals/Unit test Automation/Development/
service_ini/lib/service_ini.pm line 97, near "sub openServiceIni "
syntax error at D:/Strech Goals/Unit test Automation/Development/
service_ini/lib/service_ini.pm line 103, near "}"
Compilation failed in require at Main.pl line 9.
BEGIN failed--compilation aborted at Main.pl line 9.
 
J

Jamie

In <[email protected]>,
"ashwani" <[email protected]> mentions:

[snip]
use 5.008006;
use strict;
use warnings;

my $service_ini_file_name = 'sgutat.ini'
^^ I think you need a ";"
#sub new {

#return $this;
#}
sub openServiceIni {
print "\nEntry in service_ini::eek:penServiceIn";
my $FD=undef;
open($FD,$service_ini_file_name) || die "\ncan not open
configuration file $service_ini_file_name\n";
print "\nExit from service_ini::eek:penServiceIni";
return $FD;
} [snip]

but when i am compiling this it is giving error as
syntax error at D:/Strech Goals/Unit test Automation/Development/
service_ini/lib/service_ini.pm line 97, near "sub openServiceIni "
syntax error at D:/Strech Goals/Unit test Automation/Development/
service_ini/lib/service_ini.pm line 103, near "}"
Compilation failed in require at Main.pl line 9.
BEGIN failed--compilation aborted at Main.pl line 9.

You might consider naming it in CamelCaps, as lowercase package
names are generally a language pragma. (like strict.pm for example)

Should be harmless in your case, just a suggestion.

Syntax errors like that are kinda tricky to catch, the error
is sometimes long gone before the perl parser figures out all
is not well in the camp.

If word-wrap/tabs screwed this up, I meant a semicolon after
sgutat.ini

my $service_ini_file_name = 'sgutat.ini';


Jamie
 
T

Tad McClellan

ashwani said:
#use strict;


You lose all of the benefits of strict when you comment it out!

my %this = (SERVICE_INI_FILE_NAME => "sgutat.ini"); ^^^^^
$this{'TRACE_FILE_NAME'} = "D:/Strech Goals/Unit test Automation/
Development/input files/OC_CC_C2_002.tra";

$this->{'SERVICE_INI_FD'} = service_ini::eek:penServiceIni();
^^^^^

This $this is not that $this that appears above this.

strict would have told you that... and this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top