Main issue
What you are trying to achieve seems illogical to me, the statements about your intention seem to contradict each other: Re-initialization of the same array memory to populate a hash with values that are references to that same array. For different values you need different memory.
Assuming this is what you want your hash to contain,
$VAR1 = {
'A' => [
'a',
'b',
'c'
],
'B' => [
'd',
'e',
'f'
]
};
...what's wrong with doing it like this?
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper qw(Dumper);
my %h;
$h{A} = ["a", "b", "c"];
$h{B} = ["d", "e", "f"];
print Dumper(\%h);
Another issue
At the end of your question, you are telling us
Yes, I could do it without an array variable.
$h {A} = ("a", "b", "c");
But is there another way too? I want to have @l and no blocks.
But I don't think this line does what you expect, print Dumper ($h{A});
would show this:
'c'
You say that you didn't want blocks, I read this as memory fragmentation, but Perl doesn't let you control how memory is being used. On the contrary!
Randomization
Perl uses techniques to discourage side-channel attacks that rely on certain expectations about memory layout. Read keys - Perldoc Browser and Algorithmic Complexity Attacks for more. To give you an idea, take a look at this example, which is sure to shock a C programmer (which I think you are):
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
for (1..10) {
my %h = (
"A" => ["a", "b", "c"],
"B" => ["d", "e", "f"]
);
say keys %h;
}
Its output is like follows
AB
BA
BA
BA
AB
AB
AB
AB
BA
AB
... sometimes, but most of the time its different, also from start to start. Try it yourself!
@l
used and where it comes from etc, in reality)