Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: setting session variables

by Thilosophy (Curate)
on May 18, 2005 at 07:19 UTC ( [id://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 ).

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-29 00:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found