Options for passing Hash to a subroutine.

Discussion in 'Perl' started by chung.ley@amd.com, Mar 31, 2005.

  1. Guest

    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
     
    , Mar 31, 2005
    #1
    1. Advertising

  2. 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
     
    Sherm Pendley, Mar 31, 2005
    #2
    1. Advertising

  3. 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.
     
    Brian McCauley, Mar 31, 2005
    #3
  4. Guest

    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.
     
    , Mar 31, 2005
    #4
  5. Jim Keenan Guest

    Jim Keenan, Mar 31, 2005
    #5
  6. 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).
     
    Brian McCauley, Apr 1, 2005
    #6
  7. Eric Bohlman Guest

    Brian McCauley <> 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).
     
    Eric Bohlman, Apr 4, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    597
    red floyd
    Nov 10, 2011
  2. Scott
    Replies:
    10
    Views:
    231
    Tad McClellan
    Dec 7, 2004
  3. Replies:
    3
    Views:
    162
    Paul Lalli
    Oct 5, 2005
  4. Dean
    Replies:
    3
    Views:
    201
  5. king
    Replies:
    5
    Views:
    210
Loading...

Share This Page