Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: setting session variables

by Thilosophy (Curate)
on May 18, 2005 at 07:19 UTC ( #458094=note: print w/replies, xml ) Need Help??

in reply to setting session variables

Why do you need if/else, when both are doing the same? Is this
elsif( (!$post{'page'}) && (!$self->session->param('page')) ) { $self->session->param('page' => 1); } else { $self->session->param('page' => 1); }
not the same as
else{ $self->session->param('page' => 1); }


if($post{'page'}){ ... } elsif( (!$post{'page'}) && ...) {
also looks redundant.

How about this:

my $session = $self->session; foreach (qw[ page ] ) { $session->param( $_ => $post{$_} ? $post{$_} : 1); }
This also scales nicely with an increasing number of session variables (if all of them default to 1 ).

Replies are listed 'Best First'.
Re^2: setting session variables
by boboson (Monk) on May 18, 2005 at 09:36 UTC
    Your right, it's redudant.
    Pretty much what I want to achieve is the possibility to set a default value to my session variables, it could for example be todays year, month and day, or a boolean value, or a name.

    The session variable should be changed if the variable exists and is not empty in the querystring.

    Most of my session variables don't default to 1

    Maybe I am on the wrong track here.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://458094]
[jedikaiti]: Pretty!
[marto]: nice

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2018-03-20 16:19 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (254 votes). Check out past polls.