Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Splitting outside comments

by Sprad (Hermit)
on May 04, 2006 at 15:48 UTC ( [id://547446]=note: print w/replies, xml ) Need Help??


in reply to Re: Splitting outside comments
in thread Splitting outside comments

I don't want to delete the comments, I need to have them as-is in the final array. I just don't want to consider commas within the comments when I do the split.

Here's a typical input string (which I read in as a single line):

attr_def_OID OID, varname vartype1, /* Explanation */ varname vartype2, /* Explanation, details */ varname vartype3, /* Explanation, details, details */ varname vartype4 /* Explanation */
I want the resulting array to have 4 elements:
1: varname vartype1 2: /* Explanation */ varname vartype2 3: /* Explanation, details */ varname vartype3 4: /* Explanation, details, details */ varname vartype4 /* Explanation */
True, the comments don't get grouped with their intended lines, but that's not a problem for my application. I'm just doing some more text transformations, then joining them all back together. The important thing is that the comments come along for the ride.

This is what I'm using now to do the split, and it's working for the cases I've tried it with so far:

@elements = split(/,(?!(?:[^\/]|\/(?!\*))+\*\/)/, $str);

---
A fair fight is a sign of poor planning.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found