Options for passing Hash to a subroutine.

C

chung.ley

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
 
S

Sherm Pendley

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--
 
B

Brian McCauley

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.
 
C

chung.ley

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.
 
B

Brian McCauley

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).
 
E

Eric Bohlman

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).
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top