CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: Re: [mgpg] translate csv format: Edit Log


Feb 16, 2008, 11:58 AM

Views: 7502
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?


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)

Edit Log:
Post edited by KevinR (Veteran) on Feb 16, 2008, 12:00 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives