I'll take a stab, if I miss anything please fill it in guys.

Octavian Rasnita wrote:
> Hi and thank you. It works!
> Could you explain me please in a few words what is this line doing exactly?
> I want to learn.
> 
> print join "\n", grep defined, ($string =~ /"(.*?)"|(\w+)/g);
> 

Best thing to do is break it down in parts....

/"(.*?)"|(\w+)/g

This is the regular expression that is doing most of the work.  It says 
match all occurrences of either
1) anything between quotes ->  "(.*?)"
or -> |
2) any "one or more word character" sequences -> (\w+)  this excludes 
the spaces
g -> do it as many times as possible

$string =~ is telling it to do the above on $string

By placing the whole mess in the parentheses it forces list context and 
returns any matches in a list.

The "grep defined" is new to me in this manner but my guess is that it 
is making sure to take out any non-string occurences in the list (that 
is undefs).

Then the 'print join "\n"' is printing each of the list of matches on 
its own line.

http://danconia.org


> I don't understand starting from defined, ...
> 
> Thank you again.
> 
> It is CGI related because I want to use it in a search engine.
> I would like to test some more things, like if the + or - sign is placed
> before a word, but for the moment it is enough to test if the quotes are
> used.
> 
> 
> Teddy,
> My dear email address is [EMAIL PROTECTED]
> 
> ----- Original Message -----
> From: "Janek Schleicher" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, September 06, 2002 2:54 PM
> Subject: Re: Splitting a string
> 
> 
> Octavian Rasnita wrote at Thu, 05 Sep 2002 20:09:58 +0200:
> 
> 
>>I want to split a string but it is a little too complicated for me.
>>If it is too complicated, don't give me an answer but just a little hint
> 
> to
> 
>>the right direction.
>>
>>I have a string like the following example (used to search in a search
>>engine):
>>
>>"perl editor" free "blind accessible"
>>
>>I would like to split this string in such a way, so I would have 3
> 
> strings:
> 
>>perl editor
>>free
>>blind accessible
>>
>>In the string I could have no sub strings included in "" or more than 2
> 
> like
> 
>>in my example.
> 
> 
> my $string = q{"perl editor" free "blind accessible"};
> print join "\n", grep defined, ($string =~ /"(.*?)"|(\w+)/g);
> 
> [untested as it isn't a CGI question :-)]
> 
> Greetings,
> Janek
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> 
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to