multiple array parameters to object methods?

E

en2guy

Hi-

trying to understand object oriented perl, and have been wondering
about passing arrays as parameters to object methods.

If I pass a single array as a method parameter, it's fine, eg

$object->raiseFlags(@flags);

However, if I wanted to pass 2 arrays to an object method, I would have
to use references to objects, I think, since

$object->raiseFlags(@flags, @specialOccasions);

would append @specialOccasions to @flags to make a big jumbled list.

Are there any issues to using references as method parameters when
using objects in perl? Is there a better way to approach the problem?

Thanks
 
A

anno4000

Hi-

trying to understand object oriented perl, and have been wondering
about passing arrays as parameters to object methods.

If I pass a single array as a method parameter, it's fine, eg

$object->raiseFlags(@flags);

However, if I wanted to pass 2 arrays to an object method, I would have
to use references to objects, I think, since

Not to objects, necessarily, but array refs are the standard way
of handing in more than one array to a perl sub. Whether the sub
is a method or not is irrelevant.
$object->raiseFlags(@flags, @specialOccasions);

would append @specialOccasions to @flags to make a big jumbled list.

Are there any issues to using references as method parameters when
using objects in perl?
No.

Is there a better way to approach the problem?

Other ways, yes. Better, no.

Anno
 
E

en2guy

Not to objects, necessarily, but array refs are the standard way
of handing in more than one array to a perl sub. Whether the sub
is a method or not is irrelevant.


Other ways, yes. Better, no.

Anno

thanks for the feedback, Anno.
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top