Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is perl like java which need new()?

Status
Not open for further replies.

ppgoodboy

Programmer
Oct 9, 2006
8
JP
hello, all:
I want to know when the perl needs to new(), and how to use the *.pm in *.cgi without new()?
 
Your question makes no sense.

- Kevin, perl coder unexceptional!
 
I just studied perl from last week, and exactly I don't know perl at all, I am sorry for that so strange question. I just want to know is perl like java ? and what is is package definetion in perl ? How to use it ?
 
Perl is not really like Java at all. Specifically, object oriented programming works differently. In Java, your constructor is always called "new", as you say. In Perl, any function that returns a blessed reference is considered a constructor, although most people will use "new" by convention. If you want to read up on OOP in Perl, Google for "perltoot".
 
Code:
sub new : method
{
    my ($class, $dbo) = @_;
    
    [blue]my $self = {-dbo => $dbo};[/blue]

    bless $self, $class;
}
I saw this code at somewhere , but I didn't really understand it , who can tell me what is the [blue]-dbo[/blue] means , and what is the mean of [blue]{-dbo => $dbo}[/blue]?
 
{-dbo => $dbo } is an anonymous hash. "dbo" is the key and $dbo is the value. The next line then turns that hash into an object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top