Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Options for passing Hash to a subroutine.

204 views
Skip to first unread message

chun...@amd.com

unread,
Mar 30, 2005, 9:39:04 PM3/30/05
to
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

Sherm Pendley

unread,
Mar 30, 2005, 9:58:31 PM3/30/05
to
chun...@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

Brian McCauley

unread,
Mar 31, 2005, 11:49:03 AM3/31/05
to
chun...@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.

chun...@amd.com

unread,
Mar 31, 2005, 2:19:20 PM3/31/05
to
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.

Jim Keenan

unread,
Mar 31, 2005, 4:23:02 PM3/31/05
to
chun...@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

Brian McCauley

unread,
Apr 1, 2005, 1:19:01 PM4/1/05
to

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

Eric Bohlman

unread,
Apr 4, 2005, 12:47:27 AM4/4/05
to
Brian McCauley <nob...@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).

0 new messages