IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Interesting....

my %norm =
{
"a" => (),
"b" => (),
"c" => ()
};


all of those ()s get expanded to nothing, Perl actually sees,

my %norm =
{
"a",
"b",
"c"


Just to refresh my memory, the key is that those () are effectively nothing. If he had used a reference to an empty array, that (part) would work, no?

so, one solution would be

@empty_array;

my %norm =
{
"a" => \\@empty_array;
"b" => \\@empty_array;
"c" => \\@empty_array;
}
New The solution would have its own problems
In particular, now all values are the same, and so updating one updates them all. You were looking for this:
\nmy %norm =\n  (\n  "a" => [],\n  "b" => [],\n  "c" => [],\n  );\n

(note that you still need to fix the () vs {} issue.)

But in any case the right solution is to assume that %norm needs no initialization at all. Perl will autovivify it to be The Right Thing.

In fact that's kind of the point of having all the syntax - Perl has enough clues to be able to figure out The Right Thing and do it for you. For instance you can write:
\n  push @{ my $norm{$key} }, $value;\n

and if need be it will realize, "There is no value in %norm for $key - I need to create one and clearly it should be an anonymous array." In, say, Ruby you'd have to write two lines - one to make sure that the array was there and another to push something onto it.

(Whether the syntax is worth that benefit I'll not debate. I'm trying to explain Perl, not advocate it.)

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New <bow> thank you.
     Perl frustrations - (tuberculosis) - (45)
         Simple solution - (ben_tilly) - (10)
             Bleh. - (admin) - (3)
                 That's because you approached it wrong - (ben_tilly) - (2)
                     I'm gradually warming up to it - (deSitter)
                     That should be in the man page. - (static)
             Is this a sort of typecasting? - (tuberculosis) - (2)
                 It's a reference -NT - (Simon_Jester)
                 Sort of - (ben_tilly)
             Interesting.... - (Simon_Jester) - (2)
                 The solution would have its own problems - (ben_tilly) - (1)
                     <bow> thank you. -NT - (Simon_Jester)
         THank you for stepping on this rake - (Arkadiy) - (33)
             He was overcomplicating it - (ben_tilly) - (32)
                 Well, maybe - (tuberculosis) - (17)
                     Agreed - (ben_tilly) - (16)
                         Agree its a mistake - (tuberculosis) - (15)
                             Same here. - (admin)
                             Right - (ben_tilly)
                             Shame about the inertia. Python's design is "least surprise" - (FuManChu) - (12)
                                 When I started with Perl... - (ben_tilly) - (11)
                                     On Perl 6 - (pwhysall) - (3)
                                         Re: On Perl 6 - (Yendor)
                                         I had a nice response to this typed up - (ben_tilly) - (1)
                                             Many thanks for that - (pwhysall)
                                     We're having a little brown bag on Ruby - (tuberculosis) - (4)
                                         Re: We're having a little brown bag on Ruby - (JimWeirich) - (3)
                                             Shhh! Anonymous Todd works at some other... - (CRConrad)
                                             I might have been there - (tuberculosis) - (1)
                                                 Re: I might have been there - (JimWeirich)
                                     Re: strict -- have you seen pychecker? - (FuManChu) - (1)
                                         No I hadn't, thanks - (ben_tilly)
                 BTW Arkadiy, I'm still waiting for a response - (ben_tilly) - (13)
                     I am not saying it's shorter in C... - (Arkadiy) - (10)
                         And now for my real comment - (ben_tilly) - (2)
                             May be it's a hindsight thing - (Arkadiy) - (1)
                                 It could be many things - (ben_tilly)
                         I don't know - multimap - (Simon_Jester) - (6)
                             Re: I don't know - multimap - (Arkadiy) - (5)
                                 Why the worry about efficiency? - (ben_tilly) - (4)
                                     I worry about efficiency - (Arkadiy) - (1)
                                         Ah - (ben_tilly)
                                     C vs Perl - efficiency - untrue for me - (broomberg) - (1)
                                         Point - but you may want to rebenchmark - (ben_tilly)
                     Here's a smalltalk version - (tuberculosis) - (1)
                         Yes, think of a reference as a pointer - (ben_tilly)

It is fine to have low opinions of people's friends when they are assholes.
86 ms