On Wed, Aug 16, 2000 at 10:27:17AM -0400, Karl Glazebrook wrote:
> Nathan Torkington wrote:
> >  * current typing provides rudimentary compile-type checking.
> >    Saying:
> >      $foo = (1,3,5);
> >    gives a warning.  Saying:
> 
> this would create a $foo array

If () are array constructors, what is the hash constructor?

        $array = (1,2,3);
        $hash = qw(when Now where Here why Because);    # Is it a hash?

Well, now that I've asked the question, I've thought of an answer ...
just use Damian Conway's pair constructor:

        $hash = ('when' => 'Now', 'where' => 'Here', 'why' => 'Because');

Hmm.  I wonder how you'd pairify a list though?  Could that be one of
the unzip() or partition() routines?

Random musings (combining this and John Porter's collapse of arrays
and hashes):

        $list = qw(when Now where Here why Because); 
        while ($list) { $hash[shift $list] = shift $list; }

        $odds = map { $_%2 && $list[$_] } 0..$#list; 
        $evens = map { $_%2==0 && $list[$_] } 0..$#list; 
        $hash[$evens] = $odds;

        for ($i = 0; $i < scalar($list); $i+=2) {
            $hash[list[$i]] = $list[$i+1];
        }

Gee, I'd hate to lose simple assignment to a hash from a list.

What happens to $_ and @_?  How do I get the arguments passed to a
sub?

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to