Solved

new to PERL: explain a procedure

Posted on 2008-10-17
1
1,237 Views
Last Modified: 2012-06-22
Hello : I AM totally new to PERL
I have to change some functions in a website written in PERL.
Can someone explain me step by step(line by line) what this function does ?
especially
   $Session = CGI::Session->new($SESSION_DSN, $source || $class->genRef, $SESSION_ARGS)

(I do use PHP)

Regards





sub create_session {
    my ($class, $source) = @_;
    my $Session;
   
    do {
        $Session && warn "COOKIE exist: $source !";

        $Session = CGI::Session->new($SESSION_DSN, $source || $class->genRef, $SESSION_ARGS)
            or die CGI::Session->errstr;
    }
    while (
        not($source) && not($Session->is_new)
    );

    return $Session;
}
0
Comment
Question by:yarek
1 Comment
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 22741046
For more details on CGI::Session, see here:
    http://search.cpan.org/~markstos/CGI-Session-4.36/lib/CGI/Session.pm

#define a subroutine, named create_session
sub create_session {
    #Get the first passed parameter as $class, the second as $source
    my ($class, $source) = @_;
    
    #define a variable $Session, with no value
    my $Session;
    
    #Beginning of a loop
    do {
        #If $Session is defined, display a warning
        $Session && warn "COOKIE exist: $source !";
 
        #Set $Session to a new CGI::Session
        #For that new object, use $SESSION_DSN as the data source
        #if $source is defined, use that for the session id, otherwise use $class->genRef
        #use $SESSION_ARGS as options
        #If creating the object failed, die (exit with error value) displaying an error message
        $Session = CGI::Session->new($SESSION_DSN, $source || $class->genRef, $SESSION_ARGS)
            or die CGI::Session->errstr;
    }
    #Continue trying that while $source is not defined, and $Session is not new
    while (
        not($source) && not($Session->is_new)
    );
    
    #Return $Session to the calling procedure
    return $Session;
}

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Union rows in array that have common elements 2 102
PERL - Find newest folder 12 151
How to get all the API from website? 11 106
perl: Cleaning meta tags using RegEX 12 82
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question