Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Fix whitespace around symbols

by Corion (Pope)
on Mar 19, 2015 at 08:42 UTC ( #1120547=note: print w/replies, xml ) Need Help??

in reply to Fix whitespace around symbols

What code have you already written?

Personally, I would extract the "special" symbols and their surrounding whitespace from the first sentence and then replace the elements accordingly in the second sentence:

my %symbols = ( '/' => [], '*' => [], '-' => [], ); $_= "This is a perl script/program."; push @{ $symbols{ '/' }}, m!(\s*[/]\s*)!; push @{ $symbols{ '*' }}, m!(\s*[*]\s*)!; push @{ $symbols{ '-' }}, m!(\s*[-]\s*)!; my $target= "C'est un perl script / programme"; $target =~ s!\s*([/*-])\s*!shift $symbols{ $1 }!ge;

Replies are listed 'Best First'.
Re^2: Fix whitespace around symbols
by corfuitl (Sexton) on Mar 20, 2015 at 14:49 UTC


    Thanks for your reply. I haven't written any code because I don't know how to start. I would like to do it in perl but other script languages are welcome.

    I have tried your code and it works when the sentence contains one symbol. In case of more symbols, they are omitted from the second sentence.


      I can't replicate the problem. When I run the program with the two sentences:

      $_= "This is a perl script/program- code."; my $target= "C'est un perl script / programme - codele";

      I get as the result in $target:

      C'est un perl script/programme- codele

      ... which is what I expect. If you tell us the exact input data and the exact output data you get, maybe we can work on finding the cause.


        I don't have a standard text, but the problem appears when I have two same symbols in the same sentence. For instance,

        <p>Is this a perl script/program or a java script/program?</p> <p>C'est un perl script / programme ou un script / programme?</p>


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1120547]
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: (2)
As of 2021-04-12 03:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found