> -----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.

>
> I don't claim that we'd need that frequently.
>
> We probably do need the array version of the same problem frequently,
> though:
>
>       @matrix... = <<1 0 0 1>>;
>

Keep in mind that you're using a quoting operator. For numbers, you can just
use (0, 1, 2, 3)
and probably be better understood. (The <<list of numbers>> approach will
work, but it will take all the numbers through a string phase first,
followed by needless conversion.)

> At least we'd need it more frequently if we had it. A2 says that something
> like this will be supported, come A9.

According to popular wisdom, each Apocalypse appears after the previous one
in something like F(n) months, where F(n) is the nth Fibonacci number.
Currently we're waiting for A6, which is secretly the 7th one, since A7
slipped early. Guess how long it will be until A9?

=Austin

Reply via email to