Sponsored Content
Special Forums UNIX and Linux Applications SQL database call into Multidimensional Array using Perl Script Post 302585952 by eazyeddie22 on Thursday 29th of December 2011 06:16:40 PM
Old 12-29-2011
Java SQL database call into Multidimensional Array using Perl Script

Code:
#!/usr/local/bin/perl
use DBI;
use File::Copy;
use Time::Local;
use Data::Dumper;

-Comments Describing what I'm doing--------------
-I'm pulling information from a database that has an ID and Name. They are separated by a space and I'm trying to load them into a multidimensional array so as to manipulate Name of each element while keeping it's relationship to the ID constant.--------------------------

When I print #1, the information displays exactly how it should, but somewhere between the push and split function it goes wrong.

Code:
 $stm3 = $dbh->prepare($profile);
        $stm3->execute();
#       while (@row = $stm3->fetchrow_array)
        while (@row = $stm3->fetchrow()) {
#1               print "This is the Array: $row[0] $row[1]\n";
                @tmp = ([split / /, @row]);
                print "tmp is 0: $tmp[0] \n ";
#               push (@final, @tmp);
        #       print "E1: $final[0] E2: $final[1]\n";
        }

-I'm using the following statement to print out the results of the multi-dimensional array--------------------

Code:
for($i=0; $i<=$#final; $i++)
{
  print "i=$i\n";
  for($j=0; $j<2; $j++)
  {
    print " j = $j, Array: $final[$i][$j]";
  }
  print "\n";
}

Any thing will help.

Last edited by radoulov; 12-30-2011 at 04:50 PM.. Reason: Code tags!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

multidimensional array in perl

i'm trying to open a file with three or more columns and an undetermined, but finite number of rows. I want to define an array for each row with each element of the row as a sub array. The columns are separated by tabs or spaces. Here's the file: 12x3.12z34b.342sd3.sds 454.23.23.232 ... (9 Replies)
Discussion started by: prkfriryce
9 Replies

2. Shell Programming and Scripting

Awk multidimensional Array

Hello Experts,, Can anybody give me a brief idea what is following bold letter statement is for!! what is the term called so that I can google for it.. It seems to be an array inside another array.. awk' /TXADDR/ { txaddr=$NF } ##understood /TXDATA/ { txdata]=$NF... (1 Reply)
Discussion started by: user_prady
1 Replies

3. Shell Programming and Scripting

AWK multidimensional array

In a single dim. awk array, we can use : <index> in <array name> to determine whether a particualar index exists in the array or not. Is there a way to achieve this in a awk multi dim. array ? (4 Replies)
Discussion started by: sinpeak
4 Replies

4. Programming

multidimensional array using c++ vector

Hi! I need to make dynamic multidimensional arrays using the vector class. I found in this page How to dynamically create a two dimensional array? - Microsoft: Visual C++ FAQ - Tek-Tips the way to do it in 2D, and now i'm trying to expand it to 3D but i don't understand how is the operator working,... (0 Replies)
Discussion started by: carl.alv
0 Replies

5. Shell Programming and Scripting

Perl help: Creating a multidimensional array of subdirectories and its contents

I'm currently working with dozens of FASTA files, and I'm tired of having to manually change the filename in my Perl script. I'm trying to write a simple Perl script that'll create a 2-dimensional array containing the name of the folders and its contents. For example, I would like the output... (6 Replies)
Discussion started by: shwang3
6 Replies

6. Shell Programming and Scripting

perl-data from file save to multidimensional array

i have a file,like 1 3 4 5 6 7 8 9 i want to save it into an array. and then i want to get every element, because i want to use them to calculate. for example: i want to calculate 1 + 3. but i cannot reach my goal. open (FILE, "<", "number"); my @arr; while (<FILE>){ chomp;... (1 Reply)
Discussion started by: pp-zz
1 Replies

7. Shell Programming and Scripting

multidimensional array in awk

Hi, I was trying to process a file with the help of awk. I want to first display all the rows that contains 01 and at the end of processing I have to print some portion of all the lines. like below. Output expected: (2 Replies)
Discussion started by: ahmedwaseem2000
2 Replies

8. Shell Programming and Scripting

PERL : Bind 2D array to SQL

Hi, I am in the need of doing a bulk insert via : SQL - INSERT INTO <table> (SELECT..) OR PLSQL Block - FORALL i IN 1 .. count INSERT INTO <table>(arrayname(i)) I have a 2D array in my perl code which has the rows to be bulk inserted. Is there a way to bind the 2D array to the SQL... (4 Replies)
Discussion started by: sinpeak
4 Replies

9. Shell Programming and Scripting

Pass perl array to SQL oracle

Hello, Could someone please suggest if there is a way to pass an perl array(pass @v_array) to SQL as in below eg : #!/usr/bin/perl @v_array = (1,2,4,5,6,8); $db_userid = 'ni71/ni711'; $bufTPO = qx{ sqlplus -s << EOF $db_userid set verify off set feedback off set... (1 Reply)
Discussion started by: arunshankar.c
1 Replies

10. Shell Programming and Scripting

Multidimensional array

I am learning about bash system variables, such as $ , @ and #. I have this piece of script implementing an array and it is doing its job just fine. This is not the only array I will be using. Just for ease of maintenance and more coding I would like to have the arrays in two dimensional... (4 Replies)
Discussion started by: annacreek
4 Replies
Data::ObjectDriver::Driver::DBD(3pm)			User Contributed Perl Documentation		      Data::ObjectDriver::Driver::DBD(3pm)

NAME
Data::ObjectDriver::Driver::DBD - base class for database drivers SYNOPSIS
package SomeObject; use base qw( Data::ObjectDriver::BaseObject ); __PACKAGE__->install_properties({ ... driver => Data::ObjectDriver::Driver::DBI->new( ... dbd => Data::ObjectDriver::Driver::DBD->new('mysql'), ), }); DESCRIPTION
Data::ObjectDriver::Driver::DBD is the base class for database drivers. Database drivers handle the peculiarities of specific database servers to provide an abstract API to the object drivers. While database drivers operate on queries and database concepts like the last insert ID and binding attributes for a query, object drivers operate on objects higher level concepts like caching and partitioning. Database drivers are used with "Data::ObjectDriver::Driver::DBI" object drivers. If you are making an object driver that doesn't use "DBI", you do not need a database driver; implement your custom behavior in your "Data::ObjectDriver" subclass directly. USAGE
"Data::ObjectDriver::Driver::DBD->new($name)" Creates a new database driver of the given subclass type. That is, "new('mysql')" would create a new instance of "Data::ObjectDriver::Driver::DBD::mysql". "$dbd->init_dbh($dbh)" Initializes the given database handle connected to this driver's type of database. By default, no operation is performed. Override this method if your type of database must do further initialization that other database servers don't need, such as setting an operative time zone. "$dbd->bind_param_attributes($type)" Returns a hashref to pass to the "DBI" statement method "bind_param", to describe the SQL type of a column defined as $type in an object class's "column_defs" mapping. By default, no operation is performed. Override this method if your type of database needs such type hinting for some fields, such as specifying a parameter is a "BLOB". Note that object classes must define your custom types in their "column_defs" mappings for those classes to be compatible with your "DBD". Make sure to document any custom types you implement. "$dbd->db_column_name($datasource, $column)" Returns a decorated column name. For example, if your database requires column names to be prepended with table names, that concatenation would occur in this method. By default, "db_column_name" returns the column name unmodified. "$dbd->fetch_id()" Returns the autogenerated ID of the most recently inserted record, or "undef" if this feature is not supported. By default, "fetch_id" returns "undef". "$dbd->map_error_code($code, $msg)" Returns a "Data::ObjectDriver::Errors" code for the given database error, or "undef" if no equivalent has been defined. By default, "map_error_code" returns "undef" for every error. "$dbd->sql_for_unixtime()" Returns the SQL for querying the current UNIX time on the database server, or a UNIX time to use as the remote time. By default, "sql_for_unixtime" returns the value of perl "time()" on the local machine. "$dbd->offset_implemented()" Returns true if the database this driver represents supports "OFFSET" clauses. By default, "offset_implemented" returns true. "$dbd->can_delete_with_limit()" Returns true if the database this driver represents supports "LIMIT" clauses on "DELETE" statements. By default, "can_delete_with_limit" returns false. "$dbd->can_prepare_cached_statements()" Returns true if the database this driver can cope with preparing a cached statement. By default, "can_delete_with_limit" returns true. "$dbd->is_case_insensitive()" Returns true if the database this driver represents normally compares string fields case insensitively. By default, "is_case_insensitive" returns false. "$dbd->can_replace()" Returns true if the database this driver represents supports "REPLACE INTO" statements. By default, "can_replace" returns false. "$dbd->force_no_prepared_cache()" Returns false if the database this driver represents supports the "prepare_cached" method on its DBI database handles. By default, "force_no_prepared_cache" returns false. "$dbd->sql_class()" Provides the package name of the class responsible for representing SQL queries. This method returns 'Data::ObjectDriver::SQL', but may be overridden to return a package that has a similar interface but produces SQL that is compatible with that DBD driver. The package provided must already be loaded and available for use. LICENSE
Data::ObjectDriver is free software; you may redistribute it and/or modify it under the same terms as Perl itself. AUTHOR &; COPYRIGHT Except where otherwise noted, Data::ObjectDriver is Copyright 2005-2006 Six Apart, cpan@sixapart.com. All rights reserved. perl v5.12.4 2011-08-29 Data::ObjectDriver::Driver::DBD(3pm)
All times are GMT -4. The time now is 05:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy