Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

using Class::Struct in a module
package My::Module;
use Class::Struct;

struct Blah => {
field1 => '$',
field2 => '$'
};

sub new {
# normal constructor
}

sub f   {
my $s = new Blah; # this calls new() defined above
$s->field1 = 1;
$s->field2 = 2;
return $s;
}

package main;

my $obj = new My::Module;
my $s = $obj->f();
print "$s->field1\n$s->field2\n";

---------------------------------------------

ok, the problem is that in My::Module::f(), the statement my '$s = new Blah'
calls My::Module::new() instead of constructing a struct of type Blah.  how
can i get this code to perform the way i want?

thank you for the help.


Report this thread to moderator Post Follow-up to this message
Old Post
Christopher J. Bottaro
08-05-04 01:55 AM


RE: using Class::Struct in a module
thank you.  i guess when i was saying 'my $s = new FHEAD', it was calling
the new() in the current package.  changing it to 'my $s = FHEAD->new()'
forces it to use FHEAD's new() method.

NYIMI Jose (BMB) wrote:

>
> 
>
> use strict;
> use warnings;
> 
>
> I suppose you have some code in the above new() :-)
> 
>
> The syntax should be:
> $s->field1(1);
> $s->field2(2);
>
> 
>
> Better putting $s outside of double quote:
> print $s->field1."\n".$s->field2."\n";
> 
>
> Below is your code reviewed:
>
> package My::Module;
> use strict;
> use warnings;
> use Class::Struct;
>
> struct( Blah => { field1 => '$', field2 => '$'} );
>
> sub new {
> my($caller)=@_;
> print "normal constructor called!\n";
>       my $class=ref $caller || $caller;
>       my $self = {};
>       bless $self => $class;
> }
>
> sub f {
> my $s = Blah->new();
> $s->field1(1);
> $s->field2(2);
> return $s;
> }
>
> package main;
>
> my $obj =My::Module->new();
> my $s = $obj->f();
>
> print $s->field1."\n".$s->field2."\n";
>
>
> OUTPUT:
>
> normal constructor called!
> 1
> 2
>
>
> HTH,
>
> José.
>
>
> **** DISCLAIMER ****
>
> "This e-mail and any attachment thereto may contain information which is
> confidential and/or protected by intellectual property rights and are
> intended for the sole use of the recipient(s) named above. Any use of the
> information contained herein (including, but not limited to, total or
> partial reproduction, communication or distribution in any form) by other
> persons than the designated recipient(s) is prohibited. If you have
> received this e-mail in error, please notify the sender either by
> telephone or by e-mail and delete the material from any computer".
>
> Thank you for your cooperation.
>
> For further information about Proximus mobile phone services please see
> our website at http://www.proximus.be or refer to any Proximus agent.
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Christopher J. Bottaro
08-05-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:32 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.