I am passing a variable that needs to be evaluated with a print command. An example of my variable may look like this "variabl%e"

I understand that the best way to get around the percent problem would be to simply add another percent sign to the variable and then it would evaulate out to one percent. However, my variable is being populated from a higher level and the script is only reading out to have the one percent.

Is there an option in the print command printf that will handle this without the need of adding the extra percent?

If not, what would be the quickest way in which I could add the extra percent sign into the variable on the fly, and return the variable with the newly added percent. Also, are there any other operators that will give similar trouble when using the printf command?

Edited by starlight849: n/a

5 Years
Discussion Span
Last Post by d5e5

Could you give us a snippet of your script to illustrate what you are trying to do? Maybe it's me but I really don't understand what you mean by evaluating "variabl%e". Does the following bear any resemblance to what you want?

use strict;
use warnings;

my $variable = 1;

my $format = '%s%%';

printf $format, $variable; #1%
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.