Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Perl module symbol import versus direct invocation

by JayBonci (Curate)
on Feb 26, 2003 at 07:53 UTC ( [id://238694]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl module symbol import versus direct invocation
in thread Perl module symbol import versus direct invocation

Okay, but for instance there isn't a new method in the Date::Calc object. Wouldn't it have to auto-instantiate the object before it could call methods on itself? If it's passing a reference, what is it passing a ref to, if no object has been created?
jaybonci@starlite:~/perl$ perl -MDate::Calc -e 'my $foo = new Date::Ca +lc;' Can't locate auto/Date/Calc/new.al in @INC (@INC contains: /etc/perl / +usr/local/lib/perl/5.8.0 /usr/local/share/perl/5.8.0 /usr/lib/perl5 / +usr/share/perl5 /usr/lib/perl/5.8.0 /usr/share/perl/5.8.0 /usr/local/ +lib/site_perl .) at -e line 1


    --jaybonci

Replies are listed 'Best First'.
Re^3: Perl module symbol import versus direct invocation
by robartes (Priest) on Feb 26, 2003 at 08:03 UTC
    This is no longer in answer to you initial question, as dbp pointed out that Date::Calc does not provide an object interface, but I got curious as to what happens when you call a method on something that is not an object. Lessee...
    #!/usr/local/bin/perl -w use strict; package Test; print Test->method(); sub method { my $self=shift; return $self; } __END__ Test
    Ah, that's right - you get the package name. I knew this ;).

    So that answers your question: if no object has been created, calling a function with -> results in the function getting the package name as the first argument. This also explains the error in your script: Date::Calc::Add_Delta_Days gets 'Date::Calc' as the year, hence the usage message.

    Update: See bart's post below for some more information on -> syntax.

    CU
    Robartes-

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-04-25 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found