Click here to get back home

Stuffing @users into $self->

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Stuffing @users into $self-> Philluminati 05-01-2008
Posted by Philluminati on May 1, 2008, 9:46 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.

Phill

Posted by Philluminati on May 1, 2008, 9:49 am
Please log in for more thread options
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?

Philluminati wrote:
> 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.
>
> Phill

Posted by nolo contendere on May 1, 2008, 10:06 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
> {
> =A0 =A0 =A0 =A0 my ($class_name) =3D @_;
> =A0 =A0 =A0 =A0 my ($self) =3D {};
> =A0 =A0 =A0 =A0 bless ($self, $class_name);
>
> =A0 =A0 =A0 =A0 my $phill =3D new user;
> =A0 =A0 =A0 =A0 $phill->setId(6);
> =A0 =A0 =A0 =A0 $phill->setUsername("ptaylor");
> =A0 =A0 =A0 =A0 $phill->setPassword("password");
> =A0 =A0 =A0 =A0 $phill->setSessionKey("");
>
> =A0 =A0 =A0 =A0 #cut some code out to stop the post being enormous.
>
> =A0 =A0 =A0 =A0 my @users =3D ( $phill );
>
> =A0 =A0 =A0 =A0 $self-> =3D [ @users ];
>
> =A0 =A0 =A0 =A0 return $self;
>
> }
>
> sub login
> {
> =A0 =A0 =A0 =A0 my ($self, $username, $password) =3D @_;
> =A0 =A0 =A0 =A0 my @users =3D @$self->; =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 #<--
> THIS IS LINE 62
>
> =A0 =A0 =A0 =A0 foreach my $user (@users)
>
> =A0 =A0 =A0 =A0 #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 =3D qw( 1 two blue );
$hash =3D \@ar;

or

$hash =3D [ 'hello', 'world' ];

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?

Posted by A. Sinan Unur on May 1, 2008, 10:44 am
Please log in for more thread options
aea5-4734-906e-7062d77f201f@m44g2000hsc.googlegroups.com:

> 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->;

You are ignoring the fact that programming is a deterministic endeavor.
Successful programmers are not those who throw a bazillion variations at
a wall and see what sticks.

> I have no idea what the hell I'm doing or what any of these keywords
> mean.

Well, this would be the time to learn then, wouldn't it?

You can start by buying yourself a beginners' Perl book, oh, I don't
know, "Learning Perl" might work
(http://www.oreilly.com/catalog/lperl3/)

At the very least, you should have read:

perldoc perlreftut
perldoc perldsc

> All I want to do is pull that array back into a variable. Anyone?

If $x is a reference to an array, then @{ $x } dereferences it.

my @users = @{ $self-> };

Sinan

--
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/

Similar ThreadsPosted
Any RT users November 23, 2004, 10:11 pm
On redhat, different users = different @INC August 20, 2007, 3:00 pm
Mac Users cannot access perl CGI June 15, 2005, 9:50 pm
NewsPro Users Webring November 18, 2005, 1:15 am
Maybe difficult for English Users - but I ask anyway January 20, 2006, 3:18 am
Best way to keep registered users logged in? October 21, 2006, 4:40 am
removing users from /etc/group September 12, 2007, 11:57 pm
web based bibliography creation by users January 1, 2005, 5:18 pm
file upload failing for some users June 23, 2005, 10:17 am
perl better than python for users with disabilities? December 20, 2006, 11:11 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap