Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: remove spaces after join operation

by Loops (Curate)
on Jul 26, 2013 at 11:17 UTC ( #1046486=note: print w/ replies, xml ) Need Help??

in reply to remove spaces after join operation

Not sure this is exactly what you're looking for, but:

print join(' ',@first_sentence) =~ s/\s*([.()])\s*/$1/gr;
i am 2(but).how

Comment on Re: remove spaces after join operation
Select or Download Code
Replies are listed 'Best First'.
Re^2: remove spaces after join operation
by lakssreedhar (Acolyte) on Jul 26, 2013 at 11:27 UTC

    This error Can't modify join or string in substitution (s///) at line 5, near "s/\s*(\.\(\))\s*/$1/g;" is being shown

      Ah, is your version of Perl too old to support the /r modifier? It wont work without it. I Suppose:
      my $txt = join ' ',@first_sentence; $txt =~ s/\s*([.()])\s*/$1/g; print $txt;
      Updated to simplify regex as suggested by hdb

        ya its working now

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2015-11-27 10:38 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (724 votes), past polls