E
erehwon
hi,
I'm trying to rearrange some lists, but am having problems(!) I'm quite
new to perl...
#some vectors
$a = [( 1,2,3)];
$b = [( 3,2,3)];
$c = [( 4,5,6)];
# lists of vectors - each list starting out containing one vector
$data{$i++} = [($a)];
$data{$i++} = [($b)];
$data{$i++} = [($c)];
now I want to merge $data{0} and $data{1} so I do:
$data{0} = [(@$data{0},@$data{1})];
$data{1} = undef;
but this doesn't work. It should effectively make the lists appear as
though I'd set them up like this in the first place:
$data{$i++} = [($a,$b)];
$data{$i++} = [($c)];
(my print routine looks like this
sub printdata
{
my $t = shift;
my $c;
foreach $c (@$t) {
print "( $$c[0], $$c[1],$$c[2] )";
}
print "\n";
}
and will print with:
foreach $i (sort keys $data )
{
printdata $data{$i};
}
can anyone tell me what I'm doing wrong when trying to merge the lists?
thanks,
JJ
I'm trying to rearrange some lists, but am having problems(!) I'm quite
new to perl...
#some vectors
$a = [( 1,2,3)];
$b = [( 3,2,3)];
$c = [( 4,5,6)];
# lists of vectors - each list starting out containing one vector
$data{$i++} = [($a)];
$data{$i++} = [($b)];
$data{$i++} = [($c)];
now I want to merge $data{0} and $data{1} so I do:
$data{0} = [(@$data{0},@$data{1})];
$data{1} = undef;
but this doesn't work. It should effectively make the lists appear as
though I'd set them up like this in the first place:
$data{$i++} = [($a,$b)];
$data{$i++} = [($c)];
(my print routine looks like this
sub printdata
{
my $t = shift;
my $c;
foreach $c (@$t) {
print "( $$c[0], $$c[1],$$c[2] )";
}
print "\n";
}
and will print with:
foreach $i (sort keys $data )
{
printdata $data{$i};
}
can anyone tell me what I'm doing wrong when trying to merge the lists?
thanks,
JJ