Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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); }
?

And

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 ).


Comment on Re: setting session variables
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://458094]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-08-20 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (111 votes), past polls