srins has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
When i do change event from my select drop down from my template.
In my cgi file i got this parameter from template as
$testversions=$query->param('Testcase_Version');
where i get the output
TC11.xml*1.2
I pass this output value to my pm file to an function
sub change_event
in my pm file.
use hiSession; sub change_event { my ($this,$Testcase_Version)=@_; my $mycart = hiSession->new(); my $session = $mycart->sess_load(); # chk for session expire if ($mycart->sess_check_expire($session)) { exit(0); } my $cart_test; my %test_info; if($mycart->sess_get_key_value($session, 'Testver')) { $cart_test=$mycart->sess_get_key_value($session, 'Testver'); %test_info = %$cart_testbed_info; } print "#########Retrive from cart"; print Dumper \%test_info; print "##########################"; my %tc_ver_prev_cart; chomp(my (@testcasenameofver) = split /\*/,$Testcase_Version); $tc_ver_prev_cart{testcasename}=$testcasenameofver[0]; $tc_ver_prev_cart{testcasever}=$testcasenameofver[1]; print Dumper \%tc_ver_prev_cart; $mycart->sess_set_key_value($session,"Testver",\%tc_ver_prev_cart) +; }

Next time,i select different option in drop down for that i have got the output
TC12.xml*1.5
But i need to store previous value ie TC11.xml*1.2 also for some processing .
So,i decided to put that parameter in session and retrive it using sess_get_key_value.I have used that session module of perl.
sess_set_key_value
sess_get_key_value
But i cant able to retain the previous value .I am not getting expected output.
I am getting as
#########Retrive from CART $VAR1 = {}; ############################################ $VAR1 = { 'testcasename' => 'TC12.xml', 'testcasever' => '1.5' };
First time %testbed_info will be undef,but next time it should contain previous parameter.
Every time i am not getting anything in the hash %testbed_info.Its empty always.
But i need to retrive previous value as well as current value
something as
$VAR1 = {'testcasename' => 'TC11.xml', 'testcasever' => '1.2', 'testcasename' => 'TC12.xml', 'testcasever' => '1.5' };
from session.
my session functions are
use strict; use warnings; use CGI; use CGI qw(:standard :html3); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Data::Dumper; use URI::Escape; use vars qw($SELF_URL $session); sub sess_set_key_value { my $self = shift; my ($session, $key, $value) = @_; $session->param($key, $value) or dienice("Enter a proper key / value pair"); if ($self->is_debug_set) { my $id = $session->id(); print "SESSION ID - $id\n"; print "SESSION SET Key - $key, Value - $value\n"; } return 1; } sub sess_get_key_value { my $self = shift; my ($session, $key) = @_; my $value = $session->param($key); #dienice("Enter a proper key "); if ($self->is_debug_set) { my $id = $session->id(); print "SESSION ID - $id\n"; print "SESSION GET Key - $key, Value - $value\n"; } return $value; }
I am sure that my session is not lost.But not able to retrive data from it. Where i am going wrong in my code.I need to retrive previous value also.
can any one help me in this regard.
Thanks,
Srins.

Replies are listed 'Best First'.
Re: Getting Problem while retriving previous parameter from Session using perl
by CountZero (Bishop) on Aug 17, 2006 at 18:39 UTC
    You cannot have multiple elements in a hash with the same key! The new value will overwrite the old value.

    Save the old values as "testcasename_old" and "testcasever_old". So, at the beginning of your change_event subroutine you should retrieve the existing session values and save them under another name (see suggestions above) and only then save the new values under the "testcasename" and "testcasever"-keys.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      But i am not getting any value from the session,when i use
      if($mycart->sess_get_key_value($session, 'Testver')) { $cart_test=$mycart->sess_get_key_value($session, 'Testver'); %test_info = %$cart_testbed_info; } print "#########Retrive from cart"; print Dumper \%test_info; print "##########################";
      First time i will not get any value.But next time i should get the previous value.But i am not getting that value from seesion. Thanks, Srins.
        Did you try using one of the "standard" session modules, such as CGI::Session rather than rolling your own?

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law