----- Original Message ----- From: "Paul Johnson" <[EMAIL PROTECTED]> Newsgroups: perl.beginners To: "Rob Dixon" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Thursday, December 19, 2002 7:19 PM Subject: Re: Passing array to a function
> On Thu, Dec 19, 2002 at 03:45:56PM -0000, Rob Dixon wrote: > > > The proper way to return arrays from a function is to pass them by > > reference. > > I don't know if I would go that far. There is nothing wrong with > returning a list from a function, but if the list gets too big (handwave > here) then you might run into efficiency issues. No, but the question was about passing arrays - not lists: "How can I pass an array to a function and get values back in it?". I admit I explained how to pass an array /out/ of a function but that seemed to be what was wanted from the existing code. Satya had resorted to passing back an array by stringifying it to return a space-separated scalar, which was then split on whitespace by the calling code. Compared to that, pass by reference is the 'proper' way, always allowing for TMTOWTDI :-} > > > Change the last line of getTimeInfo() to > > > > return \@results; > > > > and dereference in the call, like this > > > > @results = @{getTimeInfo()}; > > And this copy is doing (about) the same amount of work as returning the > list in the first place. > > > "Satya Devarakonda" <[EMAIL PROTECTED]> wrote in message > > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > > Hi, > > > > > > How can I pass an array to a function and get values back in it??? Here > > > are excerpts from my code. > > Pass a reference to the array into the function and modify the array in > the function. Though in your example you don't need to pass anything in > to the function. > > You might also like to look into some of the Date modules already > available. > > -- > Paul Johnson - [EMAIL PROTECTED] > http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]