How to initialize a referenced array?

F

feltra

Hi,

Am using arrays with only references in a sub-routine. While I got
the hang of how to access an element of the array using the '->'
operator, I do not know how to intialize this array. I.e. I want to
be able to do something like

@myarr=(); $#myarr = -1;

inside the subroutine, but myarr is only a reference to an array not
the actual array...

Hope the above problem description is clear.

If anyone knows how to do this, kindly help by posting the answer or
tell me where to look...

Thanks & Best Regards,
-feltra
 
F

feltra

Thanks for the quick reply, Ben.. It works like a charm!

Basically I am copying one array to another, and within the sub, I
wouldn't know which one to init (ie. which is the receiving array),
except thru references...

It's possible that there is a better method than copying, but at least
this solution will solve my problem for now..

Thanks a lot & Best Regards,
-feltra
 
J

Jürgen Exner

[Please do not top-post, that is considered rude]
[Trying to correct]
feltra said:
Basically I am copying one array to another, and within the sub, I

Ok, so just do
@target = @source;
wouldn't know which one to init (ie. which is the receiving array),
except thru references...

???
Are you trying to say that in order to pass an array to a sub (instead
of its elements) you have to pass a reference?
It's possible that there is a better method than copying, but at least
this solution will solve my problem for now..

Still there is no need to initialize the array.
As simple
@$target = @$source
should do.

jue
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top