Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Substituting a comma only when it is preceded and followed by a bracket

by Logicus
on Nov 03, 2011 at 01:54 UTC ( #935543=note: print w/replies, xml ) Need Help??


in reply to Substituting a comma only when it is preceded and followed by a bracket

use Modern::Perl; $_= 'blah blah, blah blah blah (blah, blah, blah), blah, blah'; while($_=~ s@\(([^\)]*?)h,@\($1h;@gs){} say;
Output : blah blah, blah blah blah (blah; blah; blah), blah, blah
Not quite what was asked for, but it does produce the requested output :P
  • Comment on Re: Substituting a comma only when it is preceded and followed by a bracket
  • Download Code

Replies are listed 'Best First'.
Re^2: Substituting a comma only when it is preceded and followed by a bracket
by Logicus on Nov 03, 2011 at 01:57 UTC

    Here's the proper one;

    while($_=~ s@\(([^\)]*?),@\($1;@gs){}
      Oh hang on, ok there was no check to see if the comma was followed by a bracket, so if there was no close bracket, it would replace every comma to the right of the open bracket, which technically would be incorrect because the task specified there to be a following bracket and a single bracket by itself would not count. However as long as the two brackets are there it works fine.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935543]
help
Chatterbox?
[ELISHEVA]: Simple yes. and I did consider that. but this isn't one off . An important data source that I don't control is generating bom prefixed utf8 files and I'd rather not have to be munging files every few months.
[erix]: on teh other hand a SOPW is pretty much garanteed to get an answer from tux (and probably the module fixed)
[ELISHEVA]: plus it bugs me that something that *should* be simple, *should* work- unicode and noms aren't exactly the new kids on the block
[ELISHEVA]: well then since the obvious possible mistakes on my part have been ruled out, SOPW it is.
[ELISHEVA]: the data source, or one of them, is the OECD - they provide a *lot* of data that ought to be easily available to perl programmers.
[erix]: it might be cunning to mention the module in the title... :)
[ELISHEVA]: fancy that - a title that actually describes the problem :-)
[ELISHEVA]: but actually thanks for the reminder
[Discipulus]: DBI::CSV + utf8 = BOO?M
[erix]: in extremis we tend to forget stuff ;)

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-05-28 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?