SPUG: Question: scoping
Jacinta Richardson
jarich at perltraining.com.au
Mon Sep 15 18:51:33 PDT 2008
Ronald J Kimball wrote:
> Works for me. I suspect the problem is that MyClass's new method is not
> actually returning the blessed reference.
Works for me too. I made some minor changes to Ronald's code to flesh out
value() a little more.
#!/usr/bin/env perl
use strict;
use warnings;
my @obj;
for(my $i = 0; $i<10; $i++) {
$obj[$i] = new MyClass;
}
for(my $i = 0; $i<10; $i++) {
$obj[$i]->value("Test Value $i.");
}
for(my $i = 0; $i<10; $i++) {
print $obj[$i]->value() , "\n";
}
package MyClass;
sub new {
return bless {}, shift;
}
sub value {
my ($self, $value) = @_;
if($value) {
return $self->{value} = $value;
}
else {
return $self->{value};
}
}
--
("`-''-/").___..--''"`-._ | Jacinta Richardson |
`6_ 6 ) `-. ( ).`-.__.`) | Perl Training Australia |
(_Y_.)' ._ ) `._ `. ``-..-' | +61 3 9354 6001 |
_..`--'_..-_/ /--'_.' ,' | contact at perltraining.com.au |
(il),-'' (li),' ((!.-' | www.perltraining.com.au |
More information about the spug-list
mailing list