Hi Tanktalus, My Advisor is not available yet today, so I haven't been able to ask further questions as to why to stay away from 2D arrays like AoA, HoA, AoH, and HoH. In the meantime I've tried to get a handle of how to populate a 2D array from results returned from a select statement run against a database. I can't quite seem to understand how to do so, I have tried many methods, but none populate the array properly. I either get a blank array or nothing happens. Below is an example of what I have thus far:
use strict; my ($object_name, $object_type, $module_type, @list_of_objects, $database, $userid, $passwd); $database = 'DBI:Oracle:tdtxtasd'; print "Please enter your username:"; $userid = <STDIN>; chomp($userid); print "Please enter your password:"; $passwd = <STDIN>; chomp($passwd); use DBI; my $dbh = DBI->connect($database, $userid, $passwd) or die "Couldn't connect to database: " . DBI->errstr; my $sth = $dbh->prepare('SELECT object_name, object_type FROM user_obj +ects WHERE object_type = ?') or die "Couldn't prepare statement: " . $dbh->errstr; $module_type = "PROCEDURE"; my $rc = $sth->execute($module_type); while (($object_name, $object_type) = $sth->fetchrow()) { #push @{list_of_objects},$object_name, $object_type; print "$object_name $object_type\n"; }; $dbh->disconnect;
I know the "#push @{list_of_object},$object_name, $object_type;" line is wrong, but am not sure how to populate what I want to be a 2D array (@list_of_objects) with the two variables returned for each row ($object_name and $object_type). Additionally, once this occurs, how will I be able to reference just the $object_name from this array for each element in the array to then search a document for each $object_name. Is it a case of using foreach loops to reference each dimension in the array? Such as(extreme pseudocode to follow:
foreach i (1....n) { foreach j (1,2) { $object_name = @list_of_values[i][2]; } };
I realize this is a long post. I hope I get my point across. Let me know what you think. Thanks.

In reply to Re^3: Creating an array of structures? by newbie2perl
in thread Creating an array of structures? by newbie2perl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.