prafull has asked for the wisdom of the Perl Monks concerning the following question:

HI All Perl Masters , Want to populate value of $value in text box.

$value = qq{"Product1"};

print qq{<input type="text" name="product" value="$value" size="10">};

But value is not coming in textbox . The reason is variable contains double quote.
When it comes to value of input type , it displays in source code like this

<input type="text" name="product" value=""product1"" size="10">

Anyone knows solution to this ?

Rgds
Prafull

Replies are listed 'Best First'.
Re: issue with double quotes
by NetWallah (Canon) on Jul 07, 2010 at 05:51 UTC
    If you don't want quotes, don't put them there. Use:
    $value = qq{Product1}; # or $value = "Product1"; # Same thing
    Update: After reading ikegami's post below, i realized the O.P is trying to escape html.

    The more appropriate mechanism for that is:

    use CGI; $value = escapeHTML (qq{"Product1"});
    This will do the right thing for thing for multitudes of sins.

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

Re: issue with double quotes
by ikegami (Patriarch) on Jul 07, 2010 at 05:51 UTC

    If you don't want to set of quotes, don't place two sets of quotes.

    But what if $value actually did contain quotes? You need to convert the contents of $value into an HTML attribute

    sub text_to_html_value { my ($s) = @_; $s =~ s/&/&amp;/g; $s =~ s/"/&quot;/g; return qq{"$s"}; } my $q_value = text_to_html_value($value); print qq{<input type="text" name="product" value=$q_value size="10">};
Re: issue with double quotes
by JavaFan (Canon) on Jul 07, 2010 at 08:54 UTC
    The easiest is to use single quotes:
    print qq{<input type="text" name="product" value='$value' size="10">};
    This assumes $value does not contain a single quote - which it doesn't in your example.