>>>>> "JG" == Jenn G <practicalp...@gmail.com> writes:

  JG> When I create a package, and call its methods by both object way and
  JG> function (exported) way, how to avoid the conflict in arguments
  JG> passing?

why are you trying to do OO and procedural calls on the same subs? it
makes no sense. how will a procedural find the 'object' the method style
is going to use for its data? there is a technique for using procedural
calls with a singleton object but that requires you assume only one
object of that type ever. i don't think you seem to want that.

  JG> for exmaple,


  JG> package myclass;

  JG> require Exporter;
  JG> our @ISA = qw/Exporter/;

use base 'Exporter' ;

that will replace both of those lines.

  JG> our @EXPORT = qw/my_method/;


  JG> sub new {
  JG>     ...
  JG> }

  JG> sub my_method {

  JG>     my $self = shift;
  JG>     my @arg = @_;

        my( $self, @args ) = @_ ;

that is cleaner, faster and better.

  JG>     ...
  JG> }

  JG> __END__

  JG> But for function calling, "my $self = shift;" shouldn't be used.
  JG> So how to make both function calling and object calling work together?

well, as i asked above, where would you get the object for the function
to use? as i also said, it makes no sense to try to do what you want to
do. so explain your needs or whay you think this is needed.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to