简体   繁体   中英

Substitute, replace string with perl

I have string like this:

$string= "only this I need" .

I am new in perl, and I tried to translate a PL/SQL code in perl.
My goal is to replace " with a blank space, finally it should look like this:

$string = only this I need

In PL/SQL I use this, and is working very well:

REGEXP_REPLACE(string,'"','');

In perl I tried this, but is not working: $string=~s/"/''; receiving an error.

Please, help me, tell me what I need to read to do my job properly?

Try this it should work:

use strict;
use warnings;

my $string= '"only this I need"';

print "$string \n"; #prints "only this I need"

$string =~ s/"/ /g;

print "$string \n"; #prints only this I need

This is a way to remove quotes from string:

my $string= '"only this I need"';
$string =~ m/"([^"]*)"/;
print "$1\n";

In case if you know the first and last character is quotes, you can do this without using regex , just use substr :

my $string= '"only this I need"';
$string = substr $string, 1, -1;
print "$string\n";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM