Austin Hastings writes:
> 
> 
> > -----Original Message-----
> > From: Abhijit A. Mahabal [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, 15 April, 2004 05:13 PM
> > To: [EMAIL PROTECTED]
> > Subject: Array/Hash Slices, multidimensional
> >
> >
> > As the hash syntax is being worked out, I thought it'd be a good time to
> > ask if the following will be supported in some form:
> >
> > If I have some structure like %foo{"monday"}, %foo{"tuesday"} etc,
> > I can set their values enmass using:
> >     %foo<<monday tuesday wednesday>> = <<a b c>>;
> >
> >
> > What if I had
> >     %foo{"monday"}{"food_expenditure"}   = 10;
> >     %foo{"tuesday"}{"fuel_expenditure"}  = 100;
> >     %foo{"monday"}{"food_expenditure"}   = 15;
> >     %foo{"tuesday"}{"fuel_expenditure"}  = 150;
> >
> > Can I say %foo... = <<10 100 15 150>>;
> >     for some definition of ...?
> 
> No, but thanks to Luke Palmer's "outer" opiterator, you can get it in a
> loop.
> 
> See http://www.perl.com/lpt/a/2004/03/p6pdigest/20040328.html
> 
> Something like:
> 
>   my @workdays = <monday tuesday wednesday thursday friday>;
>   my @expense_categories = <food fuel lodging travel airfare telephone
> misc>;
>   my @error_prone_list_of_unremarked_numbers = (...);
> 
>   for outer(@workdays, @expense_categories) -> $day, $cat
>   {
>       %foo{$day}{$cat} = shift @error_prone_list_of_unremarked_numbers;
>   }
> 
> Or whatever.

Hmm.. that's all well and good, but...

    sub deref (%hash, @keylist) is rw {
        if @keylist == 1 {
            [EMAIL PROTECTED]
        }
        else {
            deref [EMAIL PROTECTED], @keylist[1...]
        }
    }

    (map { deref %foo, @^x } outer(@workdays, @expense_categories)) = 
            @error_prone_list_of_unremarked_numbers;

That doesn't work in Perl 5, but I'm allowed to speculate. :-)

Seriously, we haven't heard the word on the new slicing semantics.  All
that may be as easy as:

    [EMAIL PROTECTED]@expense_categories} =
            @error_prone_list_of_unremarked_numbers;

Though I'd love to be reassured or contradicted... hint, hint.

Luke

Reply via email to