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

I have this line in my code, it should pass to the header the value of the variable $element. The value of $element="john De Costa". But I look at the header and all I can get is the first name, it seems that nothing gets passed after the space. And I cannot change the way the value on the variable is. How can I get the entire string into to the header so I can use it later? Here is how I am passing the values to the header. print "<td bgcolor=#e0e0e0><a href=open_log_viewer.pl?=$getdata=$getdata2=&transaction=dusage_by_unit&$element><font color=#000000 size=\"2\"><b>$element</b></font></A></td><td><font color=#000000 size=\"2\"><b>T. Number of Visits&nbsp;&nbsp;</b>=</font>&nbsp;&nbsp;<font color=red size=\"2\"><b>$count{$element}</b></font>\n";

Replies are listed 'Best First'.
Re: Passing parameters
by chromatic (Archbishop) on Jul 30, 2002 at 19:41 UTC

    Spaces must be encoded in URLs. Try the URI module, or one of the encode functions in CGI.pm.

Re: Passing parameters
by Cine (Friar) on Jul 30, 2002 at 19:43 UTC
    print "<td bgcolor=#e0e0e0><a href=\"open_log_viewer.pl?=$getdata=$getdata2=&transaction=dusage_by_unit&$element\">... You are missing two ", but it is incorrect html. You should use Apache::Util's escape_html to make it into a correct tag. eg.
    print "<td bgcolor=#e0e0e0><a href=\"open_log_viewer.pl?=$getdata=$get +data2=&transaction=dusage_by_unit&". Apache::Util::escape_html($element)."\">...


    T I M T O W T D I
      I have to say thank you very much. You pointed to the right direction. By adding the " at the begging and ending of the url solved the problem. One of those days when you can't see what is right in front of you. Thank you again!!!!!
        But then you did not read the second part of my message... What if you variable contains a " that will break your script again. Go use either CGI.pm you Apache::Util to do your job.

        T I M T O W T D I
Re: Passing parameters
by BorgCopyeditor (Friar) on Jul 30, 2002 at 19:22 UTC

    I'm not sure what you mean by "passing values to the header," but I ran your code and got "john De Costa" everywhere. The only potential problem I can see is that your href string presents name-value pairs for all but the last case, where you just give & plus the name. If the "open_log_viewer" script is looking for a name-value pair there, you're going to have trouble. Is that the "header" you're talking about?

    Update: What they said. :) I was so focused on the printing thing that I forgot the HTML I learned on my mother's knee. HTML attributes should be quoted and spaces escaped in URLs.

    HTH,

    BCE
    --Your punctuation skills are insufficient!

      Obs: I will be working on my punctuation skills, but till than I need to focus on this problem. And I don't know how you are getting the intire string back, I can only get the entire string if I add %20 between the spaces, other than that I can only get the first name. Here is some more of the code for you to see it.
      foreach $element( sort keys %count) { my $a_total= sprintf "%.2f", ($count{$element}/$total_count)*100;## +################$ELEMENT################################### print "<td bgcolor=#e0e0e0><a href=open_log_viewer.pl?=$getdata=$getda +ta2=&transaction=dusage_by_unit&$element><font color=#000000 size=\"2 +\"><b>$element</b></font></A></td><td><font color=#000000 size=\"2\"> +<b>T. Number of Visits&nbsp;&nbsp;</b>=</font>&nbsp;&nbsp;<font color +=red size=\"2\"><b>$count{$element}</b></font>\n"; print "</td>\n"; print "<td bgcolor=#e0e0e0 align=\"center\"><font color=navy size=\"2\ +"><b>$a_total%</b></font></td></tr>\n"; }