about perl module use

Y

yihucd

under /home/wolf/ttt, I have program h1.pm

package h1;
require Exporter;
$aaa1=123;

our @EXPORT = qw($aaa1);


sub abc{
print "abc";
}

under /home/wolf, I have program "h2"
#!/usr/bin/perl

use ttt::h1;

print $ttt::h1::aaa1;

But how come the statement print $ttt::h1::aaa1; does not print
anything out?
 
J

Jeff Stampes

under /home/wolf/ttt, I have program h1.pm

No, you have a module. Sort of.
package h1;
require Exporter;
$aaa1=123;

our @EXPORT = qw($aaa1);

Can you explain why you're using 'our' here?
sub abc{
print "abc";
}

under /home/wolf, I have program "h2"
#!/usr/bin/perl

use ttt::h1;

print $ttt::h1::aaa1;

But how come the statement print $ttt::h1::aaa1; does not print
anything out?

Because your module doesn't know how to export things:

@h1::ISA = qw( Exporter );


HTH,
~Jeff
 
J

John Bokma

under /home/wolf/ttt, I have program h1.pm

package h1;
require Exporter;
$aaa1=123;

our @EXPORT = qw($aaa1);


sub abc{
print "abc";
}

under /home/wolf, I have program "h2"
#!/usr/bin/perl

use ttt::h1;

print $ttt::h1::aaa1;

But how come the statement print $ttt::h1::aaa1; does not print
anything out?

use strict;
use warnings;

might give some extra help.

replacing package h1; with package ttt::h1; might fix the problem.

One word of advice, use sensible names, even if it's just a test.
 
S

samwyse

under /home/wolf/ttt, I have program h1.pm

package h1;
require Exporter;
$aaa1=123;
our @EXPORT = qw($aaa1);

under /home/wolf, I have program "h2"

#!/usr/bin/perl
use ttt::h1;
print $ttt::h1::aaa1;

But how come the statement print $ttt::h1::aaa1; does not print
anything out?

Because it doesn't like you?

What happens if you print $aaa1?

How about printing the string "My program hasn't abnormally terminated"?
 
S

samwyse

Jeff said:
under /home/wolf/ttt, I have program h1.pm

No, you have a module. Sort of. [...]
Because your module doesn't know how to export things:

@h1::ISA = qw( Exporter );

Ah, but he's printing the variable using a fully qualified name, so
that doesn't matter.
 
J

Jeff Stampes

Ah, but he's printing the variable using a fully qualified name, so
that doesn't matter.

Indeed...thanks.

I has just shot myself in the foot forgetting to be ISA Exporter...so it was fresh in my
mind.

Cheers,
~Jeff
 

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,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top