Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

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


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

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Re: Re: Dereference an array reference
by fmogavero (Monk) on Apr 19, 2001 at 23:13 UTC
    There is more than one value in the array. In my example $self->tsids contains a list or an array. Its just a bunch of values returned from the database.

    I wanted to use foreach $var($self->tsids) to iterate over the list and create a new object for each item in the list.

      so $var is the array reference in question, correct? And you want all the values in $var or just the first?

      I know its taking a while but we will figure this out... :)
                      - Ant

        my $self = shift; In the next line I want to go through each item in $self->tsids which is declared as $self->{tsids} = []; thus the line
        foreach my $var($self->tsids) {
        This line my $name = new profile($var); is to create a new object for each value in $self->tsids

        I already have a DBI handle my $connection = $self->connection;

        Then I prepare my statement using a placeholder my $sth = $connection->connection->prepare( "SELECT  Last_Name = LastName, First_Name = FirstName, Middle_Name = MidName, Job_Title = JobTitle, Birthdate = Birthdate FROM table WHERE database_wide_key = ?" );

        This is probably the offending line my @names = ($var);

        This is the line where it diesmy $rc = $sth->execute(@names) or die "I'm sorry Dave, I can't do that";

        I initially got an error message that the database MS TSQL 6.5 could not implicity convert a VARCHAR to an INT which made me think that Perl was interpolating $var into a "string".

        When I use the CONVERT statement, Convert(int, varchar) ?, it tells me that it cannot convert VARCHAR ARRAY(XXXXXXX) into a INT which leads me to believe that I am incorrectly dereferencing the array.This is where I am stuck.

        The rest of the code is meant to populate the properties of the object created by the foreach loop.

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-03-29 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found