http://qs1969.pair.com?node_id=73904


in reply to Re: Re: Re: Re: Dereference an array reference
in thread Dereference an array reference

OK, feel free to point and laugh!

my $self = shift; foreach my $var($self->tsids) { my $name = new profile($var); ###profile->Name($var) my $connection = $self->connection; my $sth = $connection->connection->prepare( "SELECT Last_Name = La +stName, First_Name = FirstName, Middle_Name = MidName, Job_Title = Jo +bTitle, Birthdate = Birthdate FROM table WHERE database_wide_key = ?" + ); my @names = ($var); my $rc = $sth->execute(@names) or die "I'm sorry dave"; my $fieldnames = $sth->{NAME}; while(my $row = $sth->fetch) { for (0 .. ( scalar @{ $fieldnames } -1 )) { $_ = '' unless defined +; $_ =~ s/\s//g; my $prop = $fieldnames->[ $_ ]; my $val = $row->[ $_]; $name->$prop($val); } } }
This code fails with an error message saying that ARRAY(XXXXXX) is not a valid value, which I understand that it is not. I just can't figure out how to dereference the array reference so that ARRAY(XXXXXXX) is resolved to a number.

Replies are listed 'Best First'.
(tye)Re: Dereference an array reference
by tye (Sage) on Apr 19, 2001 at 22:59 UTC
    my @names = ($var);

    Perhaps you want: my @names = @$var; that? Or perhaps: my @names = $var->[0]; that?

            - tye (but my friends call me "Tye")
Re: Re: Re: Re: Re: Re: Dereference an array reference
by suaveant (Parson) on Apr 19, 2001 at 22:10 UTC
    This is all very confusing...
    do you want the text from between the ()? I.E. ARRAY(0xeb960) would become 0xeb960? Because that value doesn't have much practical use.

    Is this name you are looking for in the array, or is it a property of the array. Is it actual data you have put in?
                    - Ant

      I need the actual value contained in the array.

      the array contains the values of INT4 fields from a database. I need that INT4 field value. I know that ARRAY(XXXXXXX) is a reference. I don't care about the memory location. I want what's in the memory location.

      I want a SQL statement that reads "select * from rockstars where name = 'ringo' "

      What I am getting is a SQL statement that reads "select * from rockstars where name = ARRAY(XXXXXXX) "

        Ok... is there more than one entry in the array, or just one. if there are more than one entry in the array which one(s) do you want?
                        - Ant