declare structure

R

Rose

One day i found some codes by others write like this way (i can't remember
the exact codes):

a[0]->idx = 1; # or => 1?
a[0]->name = "foo";
a[0]->loc = "earth";

I doubt it's OO programing but Perl in 21 Days told me that may be another
story. I'm not using associative array because i need all 3 or more
information later and associative array may not provide convenient way for
me to retrieve the information. Could anybody shed some light on what topic
I should refer to ?
 
B

Ben Morrow

Quoth Keith Keller said:
a[0]->idx = 1; # or => 1?
a[0]->name = "foo";
a[0]->loc = "earth";

It was probably more like

$a[0]->{idx}=1;

It could also have been (unlikely)

$a[0]->idx(1);

It *could* also have been

$a[0]->idx = 1;

using something like

{
package My;

my $idx;

sub idx : lvalue method { $idx }
}

my @a = bless [], 'My';

This construction is considered a bad idea nowadays, as it's very hard to
insert a proper 'set' method later.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top