Madison,<br><br>The reason why you are experiencing this is because you are confusing procedural syntax & semantics with object-oriented syntax and semantics.<br><br>Here is object-oriented.<br><br>use My::Module;<br>my $object = My::Module->new;
<br>my $result = $object->method(@args);<br><br>Internally within My/Module.pm it probably looks something like:<br><br>package My::Module;<br><br>sub new {<br> my $class = shift;<br> return bless {}, $class;<br>}<br>
<br>sub method {<br> my $self = shift;<br> my @params = @_;<br> ... # do stuff here<br> return $value;<br>}<br><br>Notice the "my $self = shift;" and the "my $class = shift;" lines. You need to understand what "->" means.
<br><br>I could write up a huge email on this subject but really that's a waste of effort when merlyn has already done it. Please read:<br><br><a href="http://perldoc.perl.org/perlboot.html">http://perldoc.perl.org/perlboot.html
</a><br><br>It is exactly about these concepts.<br><br>Also, do you really want to do OO perl? Maybe procedure Perl modules would work for your purposes.<br><br>Cheers,<br>Richard<br><br><div><span class="gmail_quote">On 9/7/07,
<b class="gmail_sendername">Madison Kelly</b> <<a href="mailto:linux@alteeve.com">linux@alteeve.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br><br> I am quite the module n00b, so please be gentle. :)<br><br> I've got a few small, simple modules I've written that handle some<br>simple functions I use often. What I want to be able to do though is:
<br><br>my $foo=My::Module->new();<br><br> Then be able to call the function/subroutines in there like this:<br><br>my $value=$foo->function($var1, $var2);<br><br> I had tried to do:<br><br>my $value=My::Module->function($var1, $var2);
<br><br> But the first value picked up in the function is the module name... I<br>don't think I should have to say in the module<br><br>sub function<br>{<br> my ($null, $var1, $var2)=@_;<br> ...<br>}<br>
<br> In order to do this. I don't like just calling the function name (as<br>I currently do) because some of the funtion names are ambiguous. For<br>example, one module is used to validate form values. So the function
<br>'phone', 'int_num', 'real_num' and so on are provided by 'NV::Validate'.<br>If I want to validate the phone number then, I'd call:<br><br>my ($valid)=phone($form_phone_num);<br><br>
This is fairly ambiguous, and I'd much rather say either:<br><br>my $validate=NV::Validate->new();<br>my ($value)=$validate->phone($form_phone_num);<br><br> Or<br><br>my ($value)=NV::Validate->phone($form_phone_num);
<br><br> But not have the first variable passed being the module name.<br><br>Any tips, pointers or such? Would it help to show some code samples from<br>my module?<br><br> Thanks!<br><br>Madison<br>_______________________________________________
<br>toronto-pm mailing list<br><a href="mailto:toronto-pm@pm.org">toronto-pm@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/toronto-pm">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br></blockquote></div>
<br>