On Sunday 13 June 2004 02:39 am, Jeff 'japhy' Pinyan wrote:
> On Jun 10, Beau E. Cox said:
> >sub parse_words
> >{
> >    my $line = shift;
> >    my @words = ();
> >
> >    $_ = $line;
[snipped]

Thank you, japhy, and others who took the time to help me
fix my word parsing script I posted several weeks ago. I've
been busy, sorry it took so long to reply.

Here is my new, improved, word parser. It recognizes 'quotes':
 
 "" '' // () {} <> ##

and separates words on:

 whitespace = ,

print( '-', join( '-&-', parse_words( $_ ) ), "-\n" ) for( @ARGV );

sub parse_words
{
    local $_ = shift;
    my @words = ();

    while( 1 ) {
        next if /\G\s*(?:\s|,|=)\s*/gc;
        last
            unless
            /\G"(.*?)"/gc   || /\G'(.*?)'/gc   ||
            /\G\/(.*?)\//gc || /\G\((.*?)\)/gc ||
            /\G{(.*?)}/gc   || /\G\[(.*?)\]/gc ||
            /\G<(.*?)>/gc   || /\G#(.*?)#/gc   ||
            /\G(.+?)\s+/gc  || /\G(.+)/gc
            ;
        push @words, $1;
    }

    @words;
}

Boy, what an improvement!

Aloha => Beau;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to