For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2006 > What is 'new' doing?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author What is 'new' doing?
Mathew Snyder

2006-11-22, 3:57 am

In this line of code what is 'new' doing?
my $users = new RT::Users(RT::SystemUser);

Mathew
Adriano Rodrigues

2006-11-22, 7:58 am

On 11/22/06, Mathew Snyder <theillien@yahoo.com> wrote:
> In this line of code what is 'new' doing?
> my $users = new RT::Users(RT::SystemUser);


Mathew,

This is called the indirect object notation. It is invoking the method
'new' of the package 'RT::Users', with arguments ( RT::SystemUser ).

It is not recommended anymore. Most code today uses the
straightforward and unambiguous construction

my $users = RT::Users->new(RT::SystemUser);

See this link

http://perldoc.perl.org/perlobj.htm...direct-indirect

or look for the section "Indirect Object Syntax" on perldoc perlobj.

Regards,
Adriano Ferreira.
Mathew Snyder

2006-11-22, 7:58 am

Thanks!

Mathew

Adriano Rodrigues wrote:
> On 11/22/06, Mathew Snyder <theillien@yahoo.com> wrote:
>
> Mathew,
>
> This is called the indirect object notation. It is invoking the method
> 'new' of the package 'RT::Users', with arguments ( RT::SystemUser ).
>
> It is not recommended anymore. Most code today uses the
> straightforward and unambiguous construction
>
> my $users = RT::Users->new(RT::SystemUser);
>
> See this link
>
> http://perldoc.perl.org/perlobj.htm...direct-indirect
>
>
> or look for the section "Indirect Object Syntax" on perldoc perlobj.
>
> Regards,
> Adriano Ferreira.
>

Chad Perrin

2006-11-22, 7:58 am

On Wed, Nov 22, 2006 at 03:44:22AM -0500, Mathew Snyder wrote:
> In this line of code what is 'new' doing?
> my $users = new RT::Users(RT::SystemUser);


Um . . . instantiating an object?

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"The measure on a man's real character is what he would do
if he knew he would never be found out." - Thomas McCauley
Mumia W.

2006-11-22, 7:58 am

On 11/22/2006 02:44 AM, Mathew Snyder wrote:
> In this line of code what is 'new' doing?
> my $users = new RT::Users(RT::SystemUser);
>
> Mathew
>


It's equivalent to saying this:

my $users j= RT::Users->new(RT::SystemUser);

Read the "perlmod" document:

perldoc perlmod


T Baetzler

2006-11-22, 6:57 pm

Mathew Snyder <theillien@yahoo.com> asked:
> In this line of code what is 'new' doing?
> my $users =3D new RT::Users(RT::SystemUser);


It's trying to look like a Perl built-in when
in fact it's just a method of the RT::Users
class.The above code is equivalent to writing

my $users =3D RT::Users->new(RT::SystemUser);

i.e. call the method new() of the class RT::Users
with an argument of RT::SystemUser.

The important thing here is to realize that
in Perl, you can call your constructor whatever
you like - though it's a nice gesture to stick
to open standards like using "new" for it ;-) -
and that you have two equivalent notations for
method calls.

HTH,
Thomas
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com