A Perl approach to this type of thing (which I believe is what the OP requested) would probably include the use of a templating system. Template (the Template Tooklit) is one good choice. In that case your first line of code would appear in the main part of the script as:

$args->{logged_in} = some_boolean_expression;

where $args is the hash containing the arguments for Template's process method. Then in the template you'd have

[% IF logged_in %] some stuff here [% END %]

If the "some stuff here" were very large, and you find enormous IF blocks distasteful (which many do), then you could instead have

[% IF logged_in %] [% PROCESS stuff %] [% END %]

where "stuff" is the name of another template that contains only the things that should appear if the user is logged in. This is a good solution where you have a substantial amount of content to show only for logged in users, and a substantial amount of content for either situaion.

If, OTOH, the page you want the user to see is completely different depending on whether they're logged in or not, you don't need a condition in your template at all. In that case, simply have your script invoke a different template altogether, depending on the status.


In reply to Re^2: Persistent login session with restricted access by Errto
in thread Persistent login session with restricted access by kgish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.