P
pgodfrin
Greetings,
I've been told in the past to not use labels (MAIN
like this:
#!/usr/bin/perl
use strict;
use warnings;
use lib '/home/modules';
use Pgt;
MAIN:
# $ENV{TESTCD}=1;
run_code();
exit;
and I foolishly ignored that advice. Mainly 'cause the advice was not
explained and I never had any problems with using a label like this.
Now I've come across a goofy little error. When run_code() croaks, it
returns the line of the MAIN label:
Test Code not set
Use %ENV in your code at rjt line 7
The module Pgt is:
package Pgt;
use strict;
use warnings;
use Carp;
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(run_code);
$VERSION="1.0" ;
sub run_code()
{
unless(exists $ENV{'TESTCD'})
{croak "Test Code not set\nUse %ENV in your code"}
print $ENV{'TESTCD'};
} # end run_code
If I comment out the MAIN lable, then croak correctly returns the line
number of failed run_code() call. Can anyone explain why?
pg
I've been told in the past to not use labels (MAIN
#!/usr/bin/perl
use strict;
use warnings;
use lib '/home/modules';
use Pgt;
MAIN:
# $ENV{TESTCD}=1;
run_code();
exit;
and I foolishly ignored that advice. Mainly 'cause the advice was not
explained and I never had any problems with using a label like this.
Now I've come across a goofy little error. When run_code() croaks, it
returns the line of the MAIN label:
Test Code not set
Use %ENV in your code at rjt line 7
The module Pgt is:
package Pgt;
use strict;
use warnings;
use Carp;
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(run_code);
$VERSION="1.0" ;
sub run_code()
{
unless(exists $ENV{'TESTCD'})
{croak "Test Code not set\nUse %ENV in your code"}
print $ENV{'TESTCD'};
} # end run_code
If I comment out the MAIN lable, then croak correctly returns the line
number of failed run_code() call. Can anyone explain why?
pg