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

Problem with objects...hashes and arrays
Hi,
please can somebody help me and show me the way to access the single attribu
tes for my object...?
I do not have any clue how to handle the array in a hash and so on.
If u want to ask me why I am using it, also I cannot handle it....do not ask
..now really I want to use this structure cause it represents to original d
atarelationship.
But I would be happy for any help provided by u.

Here is my code example:
sub new
{
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {
Name => undef,
URLS    => [],
Switch => undef,
CodeLine => [
CodeLineName => undef,
Project => [
ProjectURL  => undef,
ProjectName =>undef,
Logfile     =>undef
]
]
};
bless($self, $class);     # but see below
return $self;
}



Best regards,

Holger Schell

SAP AG,
68789 Rot (Germany)
Non-ABAP Production Services
SAP Production
Student

Phone:  +49 6227 7- 66814
Fax:      +49 6227 78-38366
ROT15, CU.01



Report this thread to moderator Post Follow-up to this message
Old Post
Holger Schell
03-27-04 04:15 AM


Re: Problem with objects...hashes and arrays
>
> Hi,
> please can somebody help me and show me the way to access the single
attributes for my object...?
> I do not have any clue how to handle the array in a hash and so on.
> If u want to ask me why I am using it, also I cannot handle it....do
not ask...now really I want to use this structure cause it represents to
original datarelationship.
> But I would be happy for any help provided by u.
>
> Here is my code example:
> sub new
> {
>     my $proto = shift;
>     my $class = ref($proto) || $proto;
>     my $self = {
> 	    Name => undef,
> 	    URLS    => [],
> 	    Switch => undef,
> 	    CodeLine => [
> 	    	 CodeLineName => undef,
> 	    	 Project => [
> 	    	   	ProjectURL  => undef,
> 	    	   	ProjectName =>undef,
> 	    	   	Logfile     =>undef
> 	    	   	]

This last structure, 'Project' doesn't likely do what you want.  This
should probably be {} instead of [].

> 	    ]
> 	};
> 	bless($self, $class);     # but see below
>     return $self;
> }
>

Generally it helps if you can help us...

I would suggest doing a lot of reading,

perldoc perldsc
perldoc perllol
perldoc perlreftut
perldoc perlref
perldoc perlboot
perldoc perltoot

Essentially the attributes of your object are referenced through the
object like any other hash reference. So the above docs will get you
started on the learning path for references, then objects.  If you
prefer book form the LPORM book from ORA is excellent.

I would also suggest becoming acquainted with the Data::Dumper module to
help you see visually what your structure really looks like.

http://danconia.org

Report this thread to moderator Post Follow-up to this message
Old Post
Wiggins D Anconia
03-27-04 04:15 AM


Re: Problem with objects...hashes and arrays
On Mar 26, 2004, at 9:20 AM, Schell, Holger wrote:

> Hi,

Howdy.

> please can somebody help me and show me the way to access the single
> attributes for my object...?

I'll try.

> I do not have any clue how to handle the array in a hash and so on.

You my see a lot of benefit looking over some Perl Object documentation.

> If u want to ask me why I am using it, also I cannot handle it....do
> not ask...now really I want to use this structure cause it represents
> to original datarelationship.
> But I would be happy for any help provided by u.
>
> Here is my code example:
> sub new
> {
>     my $proto = shift;
>     my $class = ref($proto) || $proto;
>     my $self = {
> 	    Name => undef,
> 	    URLS    => [],
> 	    Switch => undef,
> 	    CodeLine => [
> 	    	 CodeLineName => undef,
> 	    	 Project => [
> 	    	   	ProjectURL  => undef,
> 	    	   	ProjectName =>undef,
> 	    	   	Logfile     =>undef
> 	    	   	]
> 	    ]
> 	};
> 	bless($self, $class);     # but see below
>     return $self;
> }

Let's simplify that a bit:

sub new
{
my $class = shift;
my $self = {
Name => undef,
URLS    => [],
Switch => undef,
CodeLine => [
CodeLineName => undef,
Project => [
ProjectURL  => undef,
ProjectName =>undef,
Logfile     =>undef
]
]
};
return bless $self, $class;
}

# below is a sample accessor method which can get or set Name

sub name {
my $shelf = shift;
$self->{Name} = shift if @_;
return $self->{Name};
}

On a side note, all your nested array references look like you meant
them to be hashes.  If you did, you'll want to change the [ ]s to {
 }s
in the constructor.

James


Report this thread to moderator Post Follow-up to this message
Old Post
James Edward Gray II
03-27-04 04:15 AM


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:59 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.