note
Adam
Tye, you are pushing onto a scalar. Perl usually prefers for you to push things onto an array. :)
<P><pre>
>perl -Mstrict -we "my $foo = []; push $foo, 'bar'"
Type of arg 1 to push must be array (not private variable) at -e line 1, at EOF
Execution of -e aborted due to compilation errors.
>perl -Mstrict -we "my %h; push $h{foo}, 'bar'"
Type of arg 1 to push must be array (not hash element) at -e line 1, at EOF
Execution of -e aborted due to compilation errors.
</pre>
I think what you wanted to say here was:
<code>
my %merge;
for my $key ( keys %myhash )
{
push @{ $merge{ join $;, sort @{ $myhash{$key}} } }, $key;
}
</code>
I like it though, and it helps me solve an e-mail consolidation problem I had been working on.
<BR>
-Adam
<P>
<!--
<SMALL>(ps, the above code has been tested. see comments.)</SMALL>
-->
<!-- Want Test Code? Here you go:
<CODE>
#! perl -w
use strict;
use Data::Dumper;
my %d = (
a => [ 'one', 'two' ],
b => [ 'one' ],
c => ['one', 'two'],
d => ['two', 'one'],
e => [ 'one', 'two', 'three' ]
);
my %merge;
for my $key ( keys %d )
{
push @{ $merge{ join $;, sort @{ $d{$key}} } }, $key;
}
print Data::Dumper->Dump( [\%d, \%merge], ['d','merge'] );
__END__
$d = {
'e' => [
'one',
'two',
'three'
],
'a' => [
'one',
'two'
],
'b' => [
'one'
],
'c' => [
'one',
'two'
],
'd' => [
'two',
'one'
]
};
$merge = {
'one' => [
'b'
],
'one‡˜three‡˜two' => [
'e'
],
'one‡˜two' => [
'a',
'c',
'd'
]
};
</CODE>
-->
252544
252554