Mitico Mancipe
Mitico Mancipe

Reputation: 25

How can I add double quotes? perl

I want to add double quotes to a string or variables, I haven't found much about it, I know it's done through regular expressions. For example I have this variable like this

my $ movie = "Spiderman";

or this way

my $ movie = "Lord of rings";

And I want it to look like this

$ movie = "" Spiderman "";
$ movie = "" Lord of rings "";

I would appreciate some clue or idea.

Upvotes: 0

Views: 652

Answers (2)

Izya Budman
Izya Budman

Reputation: 107

You may do this using regular expression but it's some strange wish...

$movie =~ s/(.*)/"$1"/;

Upvotes: 0

ikegami
ikegami

Reputation: 385655

Escape them.

$movie = "\"Spiderman\"";

Alternatively, you could use a different delimiter.

$movie = qq{"Spiderman"};

Since you don't interpolate or use any escape sequence, you could also switch to a single-quoted string literal.

$movie = '"Spiderman"';

On the other hand, if you're trying to programmatically add quotes, you can use the following:

$movie = '"' . $movie . '"';

(Note that it's very odd to put a space after the $. I've-never-ever-seen-it-done level of odd.)

Upvotes: 5

Related Questions