in reply to Re^2: Hash reference as a parameter
in thread Hash reference as a parameter

Hrm, interesting question. It seems more like you want a global hash which gets reset to the default values each time the function is called with the exception of the values you pass in. I still don't think a reference is the way to go, but if it works, meh. What about this:
#!/usr/bin/perl use strict; use Data::Dumper; my %hash = (); my_sub(foo => 'bar', oof => 'wha'); my_sub(pah => 'eek'); sub my_sub { %hash = ( foo => 'oop', pah => 'meh', oof => 'off', @_ ); warn Dumper(\%hash); }

Replies are listed 'Best First'.
Re^4: Hash reference as a parameter
by ramya2005 (Scribe) on Sep 12, 2005 at 22:07 UTC
    Thanks for your time. But this is not the solution that I wanted!

    My idea is very simple. If the user creates the input parameters as a hash then he can alter the hash at any time and call the function. This is what I mean by the following statements.
    my %input = {foo => 'bar', oof => 'wha'}; my_sub(\%input); $input{foo} = 'bar1'; my_sub(\%input);
      So, in this case the code I posted first works fine, right? What I am confused about is why you want to pass things like this:
      my_sub(\%hash);
      instead of like this:
      my_sub(%hash);
      But, it really doesn't matter, if the solution works for you just use it :)

      Hrm, do you want the changes to be cumulative or to reset each time?
        Thanks! Your solution works.

        Finally I did this to achieve what I wanted