Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

(jeffa) Re: package/scope question

by jeffa (Bishop)
on Nov 16, 2001 at 21:22 UTC ( [id://125858]=note: print w/replies, xml ) Need Help??


in reply to package/scope question

How about using our instead of my:
use strict; require 'framework.pl'; $framework::date = "2001-12-05"; &framework::testcase1; $framework::date = "2001-11-15"; &framework::testcase1; ------------------------------------------ package framework; use strict; our $date = "2001-11-12"; sub testcase1 { print "$date\n"; } 1; # don't forget to return true value!!
I don't use our very much, but it seems applicable here. Personally, i would opt for the more standard OO approach:
use strict; require 'framework.pl'; my $fw = framework->new(); $fw->set_date("2001-12-05"); $fw->testcase1(); $fw->set_date("2001-11-15"); $fw->testcase1(); ----------------------------------------- package framework; sub new { my $class = shift; my $self = { date => '2001-11-12' }; return bless $self, $class; } sub set_date { my ($self,$date) = @_; shift->{'date'} = $date; } sub testcase1 { print shift->{'date'}, "\n"; } 1;
Perhaps Test::Simple or Test::Unit would be helpful to you as well.

(this node updated with minor tweaks and such...)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

Replies are listed 'Best First'.
Re: (jeffa) Re: package/scope question
by pbradley (Initiate) on Nov 16, 2001 at 21:44 UTC
    when I try the our approach I get warnings and errors: use of reserved word our depricated at line.... Variable $date is not imported at framework line.. Global symbol $date requires explicit package name at ... when I try the OO approach, I get the following error: framework.pl did not return a true value at test.pl line 2. one thing I should mention that may make a difference is that I am not putting any of my files in the perl lib path. (and I hope very much to avoid doing this as the setup for the test is already complex enough without having to do this)
      Sounds like you are using an older version of Perl - try perl -v to see which version you are using.

      Like i said, i personally stick with the OO style - you need to simply stick 1; as the last line in framework.pl

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      F--F--F--F--F--F--F--F--
      (the triplet paradiddle)
      
      my bad I forgot to put the return value in.. thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125858]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 14:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found