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

Re: [MacPerl] tr ?



At 12:30 29/04/96 -0500, "Robert A. Decker" <comrade@umich.edu> wrote:
>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
>{
....
[for the rest of the code, see the original post]


Few! For a newbie you write pretty solid code!


I have good and bad news for you, and it's both the same. I've pasted your
code into a MacPerl window, changing the 'read' line with an assignment like:

        $post_info='....'; # change to test at will

and when I run the code, it works! 


So the good news is: congratulations!

The bad news: You still have your original problem. I just can't figure out
what is wrong.

Are you sure your "+" and ":" are not accidently sent as %2b and %3a (or so)
respectively? That would explain it:

      $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;

These values would be converted to "+" and ":" *after* the substitution from
"+" to space etc. Normally this is the desired effect, but perhaps not what
you want.

 
Time for a break.

>  here is the function (or is the term "subroutine" used Perl?):

Who cares, really?

In traditional languages like Basic and Pascal, you have two different
things, subroutines (procedures in Pascal) and functions. Now the *only*
difference between the two is that a function returns a value, and the other
does not.

Larry Wall and pairs have noticed this, and decided to eliminate the
difference. All subroutines return a value in Perl, and that is the value of
the last executed expression/statement before the end of the subroutine.
Even the distinction between statement and expression has become blurred:
that's why 

        1;

is a valid statement. (This is usually the last one at the end of a
'required' module file, to indicate it's succesful loading.)


It is up to you to use or ignore this return value. Me, I like to call it a
"function" if you actually use this value, and a "subroutine" if you choose
to ignore it.

In cases like this:

        open(IN,"a test file") || die "Oops! Couldn't open file!";

I'm not sure if you should call "open" a function, or not.


To round up: in your example, I'd call it a subroutine, because all that
matters are the "side effects". There isn't a returned value in a
mathematical sense.


Bye for now,
 









Bart Lateur,
Gent (Belgium)

--- Embracing the KIS principle: Keep It Simple