Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Splitting inside an array

by kilinrax (Deacon)
on Feb 05, 2001 at 22:10 UTC ( [id://56457]=note: print w/replies, xml ) Need Help??


in reply to Splitting inside an array

This looks like a job for zero-width lookahead and lookbehind assertions:
#!/usr/bin/perl -w use strict; my $str = "x:= y + z;"; my @tokens = split /\s+|(?<=\w)(?=(?:;|:=))/, $str; print join "\n", @tokens;
I don't know if you find commented regular expressions helpful, but just in case you do:
my @tokens = split / \s+ # whitespace | # or (?<=\w) # after a word character (?= # before a ..... (?: # non-backreferencing paranthesis (to pre +vent adding matches to list returned) ; # a semicolon | # or := # colon equals; add more operators to spl +it on after here ) ) /x, $str;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://56457]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found