F
fatted
Having called a function from a module, I'd like that module function
to call a function from the main script, but I can't figure out how
(had a look through perlsub, perlmod,...)
Simple Example:
####### script.pl
#!/usr/bin/perl
use warnings;
use strict;
use Readable;
my $file = 'not_there.txt';
file_readable($file);
sub write_log
{
my $msg = shift;
print $msg."\n";
}
###### Readable.pm
package Readable;
use Exporter;
@ISA = ('Exporter');
@EXPORT = qw(&file_readable);
sub file_readable
{
my $file = shift;
open(IN,"<",$file) or $main::write_log("No thanks");
}
1;
######
When I run script.pl, I get:
syntax error at Readable.pm line 9, near "$main::write_log("
Compilation failed in require at ./script.pl line 5.
BEGIN failed--compilation aborted at ./script.pl line 5.
Whats the correct way to do this?
While we're here, if, use strict; use warnings; are used in a script
does this apply to any modules which are included by the script (via
use)?
to call a function from the main script, but I can't figure out how
(had a look through perlsub, perlmod,...)
Simple Example:
####### script.pl
#!/usr/bin/perl
use warnings;
use strict;
use Readable;
my $file = 'not_there.txt';
file_readable($file);
sub write_log
{
my $msg = shift;
print $msg."\n";
}
###### Readable.pm
package Readable;
use Exporter;
@ISA = ('Exporter');
@EXPORT = qw(&file_readable);
sub file_readable
{
my $file = shift;
open(IN,"<",$file) or $main::write_log("No thanks");
}
1;
######
When I run script.pl, I get:
syntax error at Readable.pm line 9, near "$main::write_log("
Compilation failed in require at ./script.pl line 5.
BEGIN failed--compilation aborted at ./script.pl line 5.
Whats the correct way to do this?
While we're here, if, use strict; use warnings; are used in a script
does this apply to any modules which are included by the script (via
use)?