Mike Pastore wrote:
> 
> Scenario 2:
> 
>     ret = grep(/hand/, var);
> 
> *puzzled expression* "Grepping a scalar for a string? Grepping a list for
> a string? Returning a list or a scalar?"

You have failed to enter the mind of an expert perl programmer.  ;-)

grep() always treats its "second" arg as a list, even if it's a scalar,
or some other list-of-one (or none); and grep() always returns a list,
even if it's a list of one (or none).

So, in fact, you don't need to puzzle over those questions, because the
answers are the same, regardless of whether "var" was a scalar or an array.


Highlander variables acknowledge the fact that all variable types (scalar,
array, hash) are simply objects.  Objects of different classes, sure; but
still just objects.  You get no visual help in cases like

        $dog->bark();
        $cat->scratch();

as to what $dog and $cat are, nor what bark or scratch do.  You, as
programmer, need to know elsehow what bark does, and whether it's what
you want.   Analogously, for variables of (perl) class "array", you
need to know that "push" is a method, and that

        push var, things;

does what you know it does.  It doesn't help anyone to write "@var".


Similarly, in

>     bar = unshift(hats, foo);
> 
> "Okay, C<hats> is obviously a list, but is it shifting in a scalar or a
> list of things? And is it assigning to another list or a scalar to get
> the new list lenghth?"

You are asking wrong/unnecessary questions, and getting wrong answers.


-- 
John Porter

        Aus tiefem Traum bin ich erwacht.

Reply via email to