For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > February 2005 > Is this an anonymous-array allocation bug?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Is this an anonymous-array allocation bug?
Tinus

2005-02-06, 10:41 am

I don't understand the following (bug???):

I create two instances of 'Name' (kees en piet). I print them out by $kees->fprint() and $piet->fprint. Both subroutines prints out: 'kees'. It seens to me, that '$self = []' in 'Name::new' should allocate two instances of '[]' in two subsequent calls but it doesn't.

Can anyone help me?

I'am using perl-5.8.0-88.3 on a redhat shrike box.

==> package:

package Name;

sub new($$){

my $type = shift;

my $self = [];

$self[0] = shift;

bless($self,$type);
}

sub fprint($){

my $self = shift;

print("name: $self[0]\n");
}

return 1;

==> main:

use Name;

$piet = Name->new("piet");
$kees = Name->new("kees");

$piet->fprint();
$kees->fprint();

==> output:
name: kees
name: kees
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com