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?

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?

#!/usr/bin/perl;
use strict;
use warnings;

my $variable = 1;

my $format = '%s%%';

printf $format, $variable; #1%
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.