Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Re: Dereference an array reference

by suaveant (Parson)
on Apr 19, 2001 at 18:05 UTC ( #73820=note: print w/replies, xml ) Need Help??

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

You mean the name of the array? Or a value within the array?
                - Ant

Replies are listed 'Best First'.
Re: Re: Re: Dereference an array reference
by fmogavero (Monk) on Apr 19, 2001 at 19:49 UTC
    I am trying to create a new object and fill its name property with a value from the array/list.(I really don't know anymore) The name is actually supposed to be a database-wide key. I want to extract the information from the database and put it into the object.

    Here's the story that I didn't want to bore anyone with.

    When an "extract" is performed here at present, they perform too many steps. (create temp table in database, populate temp table, use "DataJunction" to export temp table info to file, clean up database)

    My idea was since they are using Perl already to parse data from outside sources, we could use Perl to do the "extracts." Perl would be perfect for that.

    Since the Product that I support will be going away (we hope), and changing to an OO thing, Ifigured that we could use OO in Perl to do "extracts" and the converse which is "Loads." This way our objects could WDDX all their information over to the new objects. Also the database would be left alone to do what it does best.

    My "extract" object gets the database-wide key, and creates a "profile" object that contains all the fields from the database. This is exactly what I wanted. This is exactly what I want because we can take the "profile" and write it to the database or the WDDX or a file and it can be populated from any source like the database, or WDDX or a file.

    If you are still awake, here is where I am slightly stuck. My "extract" opens all the proper files, and retrieves the database-wide key according to the proper parameters. Now I need to take this list(extract_object->list_of_database_wide_keys) and create a "profile" object for each one and then write it to the files.

    I keeping getting a SQL statement like "select * from table where database_wide_key = ARRAY(XXXXXXXX)"
    I just don't know how to properly dereference that array reference. I've gotten SQL errors like cant convert CHAR 'ARRAY(XXXXXXX)' to INT4 field.

    My forehead is flatter and embedded with small shards of busted monitor.

      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

        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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2022-05-28 23:35 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.