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

Re: Capitalized subroutine names and packages

by Corion (Patriarch)
on Jan 05, 2003 at 20:39 UTC ( [id://224466]=note: print w/replies, xml ) Need Help??


in reply to Capitalized subroutine names and packages

It prints Foo's constructor called, because of the following circumstances (and that's my interpretation) :

  1. The executed code lives in package main and there is a sub named Bar
  2. That sub returns a string, Foo
  3. That string result is then taken as the package name in which to call new()

To circumvent this problem, either make it that [Pp]erl dosen't see Bar as a function name :

print "Bar"->new(), "\n"; # Calls Bar::new()

or call Bar::new() manually, and specify the wanted class name on the parameter list :

my $bar = Bar::new("Bar");

I don't know where in the documentation to look to find some text on this behaviour, but most likely one of the elder Perl users can explain the sequence of events from the documentation (or correct my sequence).

perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found