Hi all,  I am now making a bookshelf program with perl.
At this very beginning, I do wonder if the below script 
can be simpler or not...

sub getQuery
{    my $queryStr = @_; my %ret;

        if (! $queryStr)  {  $ret{user} = 'system' ;  $ret{book} = 'index' ;  
$ret{page} = 0  } 
        else
            {       ( $ret{user}, $ret{book}, $ret{page} )= ($1, $2, $3) if ( 
$queryStr =~ /^([a-z_]+)\.([a-z_]+)&p=(\d+)$/i );
                    ( $ret{user}, $ret{book}, $ret{page} )= ($1, $2, 0  ) if  ( 
$queryStr =~ /^([a-z_]+)\.([a-z_]+)$/i );
                    ( $ret{user}, $ret{book}, $ret{page} )= ($1, 'index', 0  ) if  ( 
$queryStr =~ /^([a-z_]+)$/i );
            }         

       return %ret
}

#### MAIN ####

my %query = getQuery($ENV{QUERY_STRING});

### Go on for param validation ###

#### END  ####

In case, I am assuming user's query will be :
1. http://whatever.tld/cgiDir/
2. http://whatever.tld/cgiDir/?username
3. http://whatever.tld/cgiDir/?username.bookname
4. http://whatever.tld/cgiDir/?userName.bookName&p=pageNum <- PageNum is an integer of 
cause 

I know that could be somehow to change the query as a fix style and with handle
like /?user=who&book=what&page=num, so I can deal with it by hash. But does 
anyway can make the above script simpler if I really got to deal on query string 
as this way ?  ( Actually I am interested to learn what I can do to deal with this 
matching =) )

Thanks alot for any commence,
Smiley Connie =)




Reply via email to