- From: Tad J McClellan <tadmc@xxxxxxxxxxxxxx>
- Date: Mon, 26 May 2008 22:53:32 -0500
Gunnar Hjalmarsson <noreply@xxxxxxxxx> wrote:
I am writing a top-down parser in Perl for a simple grammar. I would
like to split on a change in a character set. Is there a way to split
the tokens based on a change of a character set (like changing from a /
\w+/ to /+/ or something like that.
Basically I want to be able to split var = var1 + var 2; into tokens
(var, =, var1, +, var2, ;). I could do this with split / / but I
would also like var=var1+var2; to split into the same tokens.
How can I parse these two and get the same thing?
my @tokens = split /\s*([-+=;])\s*/, $string;
my @tokens = split /\s+|\b/, $string;
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
- Prev by Date: Re: Parsing
- Next by Date: Re: reinstall perl
- Previous by thread: Re: Parsing
- Next by thread: FAQ 4.65 How can I store a multidimensional array in a DBM file?