|
Posted by Philluminati on May 1, 2008, 10:29 am
Please log in for more thread options >
>
>
> > Hi everyone.
>
> > I'm writing a SOAP Server in perl and I need/want to use objects. I
> > have an array called @users which is populated in sub new. I want to
> > store this array in my $self variable which is passed to all functions
> > and then pull it out later. Can somebody help me?
>
> > sub new
> > {
> > my ($class_name) = @_;
> > my ($self) = {};
> > bless ($self, $class_name);
>
> > my $phill = new user;
> > $phill->setId(6);
> > $phill->setUsername("ptaylor");
> > $phill->setPassword("password");
> > $phill->setSessionKey("");
>
> > #cut some code out to stop the post being enormous.
>
> > my @users = ( $phill );
>
> > $self-> = [ @users ];
>
> > return $self;
>
> > }
>
> > sub login
> > {
> > my ($self, $username, $password) = @_;
> > my @users = @$self->; #<--
> > THIS IS LINE 62
>
> > foreach my $user (@users)
>
> > #more code....
>
> > }
>
> > how I get this message in my VB Soap Client:
>
> > Can't use string ("user_management") as an ARRAY ref while "strict
> > refs" in use at user_management.pm line 62.
>
> This message means that $self-> is returning a string, and
> not an arrayref, so you can't dereference it as an array.
>
>
>
> > My question is how to I put an array into a hash (if $self is one. I
> > don't really know) and how do I get it out again intact?
>
> If by 'put an array into a hash' you mean assign an arrayref value to
> a hash key, then:
>
> my @ar = qw( 1 two blue );
> $hash = \@ar;
>
> or
>
> $hash = [ 'hello', 'world' ];
Ok, thanks dude. So if I have my code do this:
$self-> = \@users;
how do I pull the data out again later when I need it?
I've tried:
my @users = ref $self->; //same message as above
my @users = @$self->;
my @users = $self->;
my @users = map $self->; //gave 500 internal server err
my @users = ( $self-> ); //same as original err
my @users = scalar $self->;
I have no idea what the hell I'm doing or what any of these keywords
mean. All I want to do is pull that array back into a variable. Anyone?
|