homepage Welcome to WebmasterWorld Guest from 54.198.130.203
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
parsing a search string
treating stuff in quote marks as one word
basenotes




msg:444725
 11:09 am on Mar 24, 2006 (gmt 0)

Is there a preferred way of doing this?

At the moment, I'm splitting the string into words, then going through each word one by one.

If the word starts with a quote mark, add it to the next word until it finds a word ending in a quote mark.

Is there a better way?

Thanks

 

perl_diver




msg:444726
 7:18 pm on Mar 24, 2006 (gmt 0)

the question is really too vague to answer, post some sample data you are searching and the code you are currently using and the results you are trying to achieve.

basenotes




msg:444727
 8:11 pm on Mar 24, 2006 (gmt 0)

sorry, I'll try to be more concise.

If I have a search string, such as:

decorated "blue widgets" "red widgets" sandy leaf.

What is the best way of splitting that string up, so that I have an array with the following data:

- decorated
- blue widgets
- red widgets
- sandy
- leaf

currently, I'm splitting the string with split(/ /) to get the individual words, then piecing together the quoted words

cheers

perl_diver




msg:444728
 10:05 pm on Mar 24, 2006 (gmt 0)

maybe there is a better way, but here is one way:


my $var = qq~decorated "blue widgets" "red widgets" sandy leaf.~;
$var =~ s/("[^\"]*")/unspacify($1)/ge;
my @array = split(/\s+/,$var);
s/\^//g for @array;
print map{"$_\n"} @array;
sub unspacify {
#replaces spaces within quoted words with ^
my $string = shift;
$string =~ s/\s/\^/g;
return($string);
}

basenotes




msg:444729
 12:38 am on Mar 25, 2006 (gmt 0)

thank you

Brett_Tabke




msg:444730
 4:27 am on Mar 27, 2006 (gmt 0)

Then if you want to get fancy - add +- altavista syntax...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved