[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] tr ?




  Thanks to everyone that helped me with my last question about counting
the lines in a document. I made many of the suggested changes. You were
right (Peter Hartuuk?), I hadn't discovered interpolation yet. I hope
everyone doesn't mind such basic questions. 
  I'm trying to learn as much as I can from a book and handbook I own, but
they don't often help me for specific problems that come up. Here's another
basic question (I think it is. I just can't seem to figure it out though).

Here's how I call a function:
if ($method eq "POST") {
   &parse_form_data(*form);
...



and here is the function (or is the term "subroutine" used Perl?):
sub parse_form_data
{
   local (*FORM_DATA) = @_;
                        
   local ( $request_method, $post_info, @key_value_pairs, 
           $key_value, $key, $value);

   read (STDIN, $post_info, $ENV{'CONTENT_LENGTH'});

   @key_value_pairs = split (/&/, $post_info);
                        
   foreach $key_value (@key_value_pairs) {
      ($key, $value) = split (/=/, $key_value);
      $value =~ tr/+/ /;   #this is where I have problems. See below.
      $value =~ tr/:/;/;   #this is where I have problems. See below.
      $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;

      if (defined($FORM_DATA{$key})) {
         $FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value);
      } else {
         $FORM_DATA{$key} = $value;
      }
   }
}

  When I look at my values returned from the function there have been no
translations. In other words, all ":" characters I entered are still ":"
characters and not ";" characters.
  I would also like to translate any "return" characters that are sent with
the form. Would that be the \n or \r character? Or something else?

rob
---------------------------------------------------
This message was created and sent using the Cyberdog Mail System
---------------------------------------------------