D
doug
Does anyone know how to set a local variable in a package by passing a
hash? ie: I basically want to pass the values to a package and if the
varaibles exist in the package space then set the values, if they do
not exist then ignore them.
I could do this using a hash, but I wanted to try this method with
local variables.
#!/opt/third-party/bin/perl -w
use strict;
use defined2;
{
my $hash_key = 0;
my ( %attrib ) = @ARGV;
my $d = new defined2();
$d->setValue( x => 102, y => 99, z => 'Loretta' );
$d->printAll();
}
exit 0;
package defined2;
use strict;
{
my $x = 20;
my $y = 25;
my $z = 'douglas';
sub new {
my $object = shift;
return bless {}, $object;
}
sub setValue {
my $self = shift;
my %args = @_;
foreach my $key ( keys %args ) {
no strict;
*{"$key"} = sub { $args{$key} };
}
}
sub printAll {
my $self = shift;
print "x is [ $x ]\n";
print "y is [ $y ].\n";
print "z is [ $z ].\n";
}
}
1;
thanks
dn
hash? ie: I basically want to pass the values to a package and if the
varaibles exist in the package space then set the values, if they do
not exist then ignore them.
I could do this using a hash, but I wanted to try this method with
local variables.
#!/opt/third-party/bin/perl -w
use strict;
use defined2;
{
my $hash_key = 0;
my ( %attrib ) = @ARGV;
my $d = new defined2();
$d->setValue( x => 102, y => 99, z => 'Loretta' );
$d->printAll();
}
exit 0;
package defined2;
use strict;
{
my $x = 20;
my $y = 25;
my $z = 'douglas';
sub new {
my $object = shift;
return bless {}, $object;
}
sub setValue {
my $self = shift;
my %args = @_;
foreach my $key ( keys %args ) {
no strict;
*{"$key"} = sub { $args{$key} };
}
}
sub printAll {
my $self = shift;
print "x is [ $x ]\n";
print "y is [ $y ].\n";
print "z is [ $z ].\n";
}
}
1;
thanks
dn