in reply to Re: Code works fine, but in subroutine does not... help plz!
in thread Code works fine, but in subroutine does not... help plz!

Yes I'm still confused by how this is supposed to work.

Here's how it's supposed to be, surely:

I think there's a fundamental problem with the way you're trying to do this.



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
  • Comment on Re^2: Code works fine, but in subroutine does not... help plz!

Replies are listed 'Best First'.
Re^3: Code works fine, but in subroutine does not... help plz!
by Stenyj (Beadle) on Apr 09, 2005 at 01:58 UTC
    Here's some sample scripts so it's clearer what I'm attempting to do & how everything works:

    Login script:
    #!c:/apache/perl/bin/perl.exe -wT use CGI; use strict; use CGI::Session; use HTML::Template; use MyAppCommon; my $foo = new CGI; my $alias = $foo->param('alias'); my $userID = 123; #normally would be pulled from DB, but keeping the c +ode as simple as possible for testing purposes my $empty; my $session = new CGI::Session(undef, $empty, {Directory=>"c:/apache/s +essions"}); $session->expire('+18h'); $session->param("id", $userID); $session->param("alias", $alias); my $cookie = $foo->cookie(-name => 'main', -value => $session->id, -expires => '+18h', -path => '/'); print $foo->header(-cookie => $cookie); MyAppCommon::topPublic(); my $template=HTML::Template->new(filename=>"c:/apache/templates/main/l +ogin.tmpl"); $template->param(ALIAS => $alias); print $template->output; MyAppCommon::bottomPublic($alias);

    One of the many pages that contain very similar coding (a page that simply wants to check if the user is logged in or not, and does NOT want to log them in if they're not... ie. does NOT create a session if they're not logged in... it only wants to check if they are & retrieve relevant session variables if they are logged in:

    #!c:/apache/perl/bin/perl.exe -wT use CGI; use strict; use CGI::Session; use HTML::Template; use MyAppCommon; my $foo = new CGI; print $foo->header(); my $sid = cookie('main') || undef; my @sessionInfo; my $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache/ses +sions'}); if ( $session->is_new() ) { $session->delete(); } MyAppCommon::topPublic(); my $template=HTML::Template->new(filename=>"c:/apache/templates/main/h +ome.tmpl"); print $template->output; MyAppCommon::bottomPublic($alias, $userAccess, $membership);

    IF I comment out the following code of the above script:
    my $sid = cookie('main') || undef; my @sessionInfo; my $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache/ses +sions'}); if ( $session->is_new() ) { $session->delete(); }

    and replace it with:
    &test; sub test { my $sid = cookie('main') || undef; my @sessionInfo; my $session = new CGI::Session(undef, $sid, {Directory=>'c:/apache +/sessions'}); if ( $session->is_new() ) { $session->delete(); } return 1; }
    I get the error I mentioned.

    " on every page, you check whether there's a session logged in or not # depending whether there is one, you do whatever you need to do"

    This is exactly what I want to do. Using the sessions ID, I want to determine if one exists with that session ID and to *NOT* create one if it doesn't exist.