On Jun 21, Connie Chan said: >sub getQuery { > my $queryStr = @_; my %ret;
You mean: my ($queryStr) = @_; or my $queryStr = shift; or my $queryStr = $_[0]; > 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 >} I guess I would write my function something like this: sub getQuery { my %ret = ( user => 'system', book => 'index', page => 0, ); my $query = shift or return %ret; if ($query =~ m{^(\w+)(?:\.(\w+)(?:&p=(\d+))?)?$}) { $ret{user} = $1; $ret{book} = $2 if $2; $ret{page} = $3 if $3; } return %ret; } >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 =) ) If you want to deal with your own specification for sending data to your program, that's totally fine. If you want to use full-fledged CGI queries, though, please consider the CGI.pm module instead of a hand-rolled solution. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]