Professional Web Applications Themes

Passing Hash table to function? - PERL Beginners

I have a hash table which contains values like my %enumerations = ( #mystat mode 'edcf' => '1', 'hcf' => '2', #admin state 'disable' => '0', 'enable' => '1', ); I have created a library of common functions and the above mentioned hash table is present in my each script, each script is calling the library,where it is using the hash table values. For some test cases application is returning disable value as 3, and hcf has a value 4. Any one solution can solve my problem 1. How do i pass hash table to function? 2. Once the hash ...

  1. #1

    Default Passing Hash table to function?

    I have a hash table which contains values like
    my %enumerations = (
    #mystat mode
    'edcf' => '1',
    'hcf' => '2',
    #admin state
    'disable' => '0',
    'enable' => '1',
    );
    I have created a library of common functions and the above mentioned hash
    table is present in my each script, each script is calling the
    library,where it is using the hash table values. For some test cases
    application is returning disable value as 3, and hcf has a value 4.

    Any one solution can solve my problem

    1. How do i pass hash table to function?
    2. Once the hash table is set my program refers to this table and i want to
    change the hash table values with each executing script which is not
    happening, its still refering to the old hash table values and my test is
    failing. So how do I reset values in hash table?
    Tushar Gokhale Guest

  2. #2

    Default Re: Passing Hash table to function?

    On Jan 19, 2004, at 5:26 AM, Tushar Gokhale wrote:
    > I have a hash table which contains values like
    > my %enumerations = (
    > #mystat mode
    > 'edcf' => '1',
    > 'hcf' => '2',
    > #admin state
    > 'disable' => '0',
    > 'enable' => '1',
    > );
    > I have created a library of common functions and the above mentioned
    > hash
    > table is present in my each script, each script is calling the
    > library,where it is using the hash table values. For some test cases
    > application is returning disable value as 3, and hcf has a value 4.
    >
    > Any one solution can solve my problem
    >
    > 1. How do i pass hash table to function?
    I suspect you may be looking for references here, though I'm not sure I
    understand the problem completely. Here's how you might use references
    to pass the above hash around:

    do_something( \%enumerations }; # pass hash by reference

    sub do_something { # example routine
    my $enums = shift; # fetch reference
    print $enums->{enable}, "\n"; # use hash
    $enums->{enable} = 42; # alter hash
    print $enums->{enable}, "\n"; # see results
    }

    print "$enumerations{enable}\n"; # show original hash is altered
    > 2. Once the hash table is set my program refers to this table and i
    > want to
    > change the hash table values with each executing script which is not
    > happening, its still refering to the old hash table values and my test
    > is
    > failing. So how do I reset values in hash table?
    I'm not sure I understand this question at all. Is the hash being
    written to a file and read back in? Please, give some more details and
    I will try to help.

    James

    James Edward Gray II Guest

  3. Moderated Post

    Default Re: Passing Hash table to function?

    Removed by Administrator
    Tushar Gokhale Guest
    Moderated Post

  4. Moderated Post

    Default Re: Passing Hash table to function?

    Removed by Administrator
    James Edward Gray II Guest
    Moderated Post

Similar Threads

  1. Question translate xml file into hash table using perl
    By veerubiji in forum Perl / CGI
    Replies: 0
    Last Post: September 30th, 12:00 PM
  2. Options for passing Hash to a subroutine.
    By chung.ley@amd.com in forum PERL Modules
    Replies: 6
    Last Post: April 4th, 04:47 AM
  3. Replies: 2
    Last Post: September 29th, 07:11 PM
  4. Passing a hash to a function
    By Mark Healey in forum PERL Miscellaneous
    Replies: 2
    Last Post: August 25th, 05:41 AM
  5. [PHP-DEV] hash table question
    By Ard Biesheuvel in forum PHP Development
    Replies: 0
    Last Post: August 13th, 03:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139