
KevinR
Veteran

Feb 16, 2008, 11:58 AM
Views: 3709
|
|
Re: [mgpg] translate csv format
|
|
|
It's a bit hard to answer your question without a better understanding of your data and how it's structured. The answer is if it works like you have it then you are not doing anything technically wrong. But there might be better ways to accomplish whatever it is your script is doing. Have you tried just passing the hash in (not using a reference) and getting back out as a hash?
foo(%hash); sub foo { my %hash = @_; } Perl does not send a hash to the function, it just sends a list of strings or scalars, this is called "flattening". But you can reconstruct the hash (or array) by packing it back into a hash on the receiving end like I did above. When you have complex data like you have, it is almost always easier to use a reference to the data, which is just one string (the memory address of the data) which you dereference later to get the data back out of the reference. It's hard to look at some code like you posted and know if it is doing something the right way or not (at least for me it is) because it may be part of a larger program. At a glance you code is overly complicated and verbose, but you may be just in the process of trying to learn how to do things, like use references and subroutines and such and the code is not meant to be as well written as maybe it could be. Not that there is anything terribly wrong that I can see, overly verbose code is better than too terse in my opinion. -------------------------------------------------
(This post was edited by KevinR on Feb 16, 2008, 12:00 PM)
|