Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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

by JavaFan (Canon)
on Nov 02, 2011 at 22:52 UTC ( #935516=note: print w/replies, xml ) Need Help??

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

my $str = do {my $i; join "", map {$_ eq '(' ? $i++ : $_ eq ')' && $i +? $i-- : $_ eq ',' && $i ? ($_ = ';') : 0; $_} split '[(,)]', $str};
This assumes the parenthesis are balanced.

But what should happen on:

? The comma here is preceded and followed by a bracket - preceded by an opening paren, and followed by a closing paren even. If such a comma should be replaced as well, one might use something like (untested):
substr($str, index($str, "("), rindex($str, ")") - length($str)) =~ s/ +,/;/g;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935516]
[marto]: failing that see the README
[mark4]: I installed "PAR" from the ppm install window. pp.exe. did not show up.
[marto]: it should just be a script, pp, or on windows pp.bat, post install you should just be able to call pp -x packed.exe as the PPM package should put everything required into the appropriate path
[marto]: ah, some time ago pp became it's own package, try searching your repo for PAR::Packer
[marto]: again, Strawberry + cpanm for the win: cpanm pp to install

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2018-01-19 14:19 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (218 votes). Check out past polls.