469,310 Members | 2,439 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,310 developers. It's quick & easy.

Options for passing Hash to a subroutine.

Hi,

Another newbie question...

I have to write a program that process a huge amount of data; the end
results will be a number of different reports. I will prefer to write
a separate library/perl script for each of the reports to
separate/isolate them into their own files... However, how do I "pass"
this huge data to the "report_function" that is in their own file
without too much overhead... From what I understand, if I tried to
pass the "hash" as a parameter to the function, the function will
create a "copy" of it, which would be a significant overhead in terms
of memory and time since I am using multiple-level hash tables with
data in the Megs.... It seems that my only option is using "global",
but from what I read and also my personal experience, it seems that we
should avoid global variable as much as we can.... Can anyone give me
other options or alternatives?

Thanks....

--Chung

Jul 19 '05 #1
6 11342
ch*******@amd.com wrote:
From what I understand, if I tried to
pass the "hash" as a parameter to the function, the function will
create a "copy" of it


Pass a reference to the hash. For details, have a look at:

perldoc perlreftut
perldoc perldsc
perldoc perllol

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Jul 19 '05 #2
ch*******@amd.com wrote:
Newsgroup: comp.lang.perl,comp.lang.perl.modules
The newsgroup comp.lang.perl ceased to exist some time in the previous
millenium. I suggest you break into your NNTP server admin's office and
remove the skeleton.
From what I understand, if I tried to
pass the "hash" as a parameter to the function, the function will
create a "copy" of it,
If you unroll it into a list yes, but see FAQ "How can I pass/return a
.... Hash...?"

Those who will not learn from the FAQ are comdemned to repeat it.
which would be a significant overhead in terms
of memory and time since I am using multiple-level hash tables with
data in the Megs....


But the copy would only be a shallow copy anyhow.

Jul 19 '05 #3
Thanks for the response... Sorry, I didn't read the FAQ close
enough... I somehow missed that...

By the way, do you have a recommendation for a good newsgroup for
begineers?

I will read up on what is a shallow copy...

Thanks again.

Jul 19 '05 #4
ch*******@amd.com wrote:
By the way, do you have a recommendation for a good newsgroup for
begineers?

http://www.nntp.perl.org/group/perl.beginners (though you'll probably
want to read it in a newsreader rather than the web interface)

and my old favorite:

http://groups.yahoo.com/group/perl-beginner/

HTH

jimk

Jul 19 '05 #5

ch*******@amd.com wrote:
Thanks for the response... Sorry, I didn't read the FAQ close
enough... I somehow missed that...
Fair enough, it happens.
By the way, do you have a recommendation for a good newsgroup for
begineers?


My advice to beginners is read the posting guidelines for this newsgroup
and stay here.

If you ask the occasional question that is off-topic or is a FAQ or is
documented in the obvioius place in the reference manuals we'll give you
a helpful but brusque answer. (Maybe just a pointer to the relevant
manual or a suggestion to go ask elsewhere).

If you take it like a man (as you did) then you'll fit in just fine here.

The people who have a problem here are the ones who go out of their way
to make it clear that they value the time of the people they are asking
to help them much less than they value their own.

The trouble with fora where this sort of behaviour is tollerated is that
those fora are unlickely attact all the best people to answer questions.
(Some of the best people do hang out it such fora - just not many and
usually not for long).

Jul 19 '05 #6
Brian McCauley <no****@mail.com> wrote in news:d2k2vn$iin$1
@sun3.bham.ac.uk:
If you take it like a man (as you did) then you'll fit in just fine here.


In the interest of non-sexism, how about making that "if you take it like
an adult" instead (since a man can differ from a non-man in two different
ways, and it's the "maturity" dimension that's relevant here).
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stephen Travis | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.