Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Re: Re: Dereference an array reference

by suaveant (Parson)
on Apr 19, 2001 at 21:22 UTC ( [id://73885]=note: print w/replies, xml ) Need Help??


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

Ahhh! To dereference an array ref, you can do the following @{$ref} or to get individual numbered elements do $ref->[0] $ref->[3] whatever the index is. So if your name is the first element in the arrayref $name, you would get it by doing $name->[0]

is that more what you were looking for?
                - Ant

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Dereference an array reference
by fmogavero (Monk) on Apr 19, 2001 at 21:52 UTC
    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.
      my @names = ($var);

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

              - tye (but my friends call me "Tye")
      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) "

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://73885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found