I'll embed some comments in your code.

# good idea :-) use strict; # There are many theories on why this is a bad idea. # My personal favourite is keeping the scope of a variable # as small as possible. Larger scope means that when I'm # trying to read your code, I need to go back farther in # the program to find out it's a lexical, and to find out # who may have changed the value. # Another reason I know to change this is to create and initialise # the variable at the same time - it means having no undef # variables (unless you explicitly want it to be undef). # For example, there is no reason to have $database undefined. # That would be an error. By combining the my with the # initialisation, then there is no point in the program # where you could be accessing an undefined $database. #my ($object_name, # $object_type, # $module_type, # @list_of_objects, # $database, # $userid, # $passwd); # create/initialise. my $database = 'DBI:Oracle:tdtxtasd'; print "Please enter your username:"; my $userid = <STDIN>; chomp($userid); print "Please enter your password:"; # You can super-search on passwords - there are ways to # do this without echoing to the screen. I think it's # in code snippets - and I think I contributed to it ;-) my $passwd = <STDIN>; chomp($passwd); # some people put all use's at the top. Some put them # close to where they're used. I'm not convinced one is # better than the other, so this is just FYI. use DBI; # here's a my which initialises. Good choice :-) 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; my $module_type = "PROCEDURE"; my $rc = $sth->execute($module_type); my @list_of_objects; while (($object_name, $object_type) = $sth->fetchrow()) { print "$object_name $object_type\n"; # push a scalar onto the list. That scalar is an array ref. # in this case, a ref to an anonymous array. push @list_of_objects, [ $object_name, $object_type ]; }; $dbh->disconnect;
To read it back out:
foreach my $object (@list_of_objects) { my @values = @{$object}; # do whatever. }
Hope that helps!


In reply to Re^4: Creating an array of structures? by Tanktalus
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.