Using Apache::Session for storing form data as opposed to database columns

Discussion in 'Perl Misc' started by ioneabu, Dec 28, 2004.

  1. ioneabu

    ioneabu Guest

    I realize that searching for data this way is not as efficient, but it
    makes it easy if a form changes, there is no need to change a database
    structure. I was wondering if others do it this way, saving all of
    their web form data to a hash and putting it in Apache::Session to call
    out later with the session id number. It's like leaving your clothes
    at the dry cleaners and taking a ticket home to retrieve the clothes at
    a later time.

    Here is a sub I wrote to handle the work:

    sub session_handler
    my ($dbh,$hash_ref,$sess_id_ref,$action) = @_;
    my %session;
    tie %session, 'Apache::Session::MySQL', $$sess_id_ref,
    {Handle=>$dbh, LockHandle=>$dbh};
    $$sess_id_ref = $session{'_session_id'};
    if ($action =~ /write/i)
    {$session{$_} = ${$hash_ref}{$_} for keys %{$hash_ref}}
    elsif ($action =~ /read/i)
    {${$hash_ref}{$_} = $session{$_} for keys %session}
    elsif ($action =~ /delete/i) {tied(%session)->delete}

    the hash referenced by $hash_ref is either filled with data or is to be
    filled with data depending on the value of $action. Same with

    It is tested and appears to work fine. I started with a big mess of
    code and tried to clean it up by using statement modifiers.

    Any advice on code would be appreciated and on the soundness of the
    overall method of using Apache::Session for storing fairly large
    amounts of important data from html forms.


    ioneabu, Dec 28, 2004
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.