hi there, I have some database output that looks like this
result is this (ive delimited with a pipe for ease of reading)
Now, i know how to create a hash of hashes manually from this data, and it works just fine, see below
however, can somebody advise me how I would get this hash of hashes auto-generated straight from the database using DBI ? currently all I have is
but i really dont know how I can self populate my hash of hashes directly from the SELECT statement which produces the table above..somebody suggested using fetchrow_hashref hence why i have added it in the line above, but it doesnt seem to do what i want
Any help or guidance on this would be greatly appreciated ( i am very new to perl)
This is driving me mad, where am I going wrong?
The relevant segment of code:
sub getndsybcons {
my @servers=@{$_};
my @sybservers=@{$_};
my %results;
foreach my $server(@servers) {
my $biggestsyb;
my $biggestsybval=0;
... (9 Replies)
I have a script with dynamic hash of hashes , and I want to print the entire hash (with all other hashes).
Itried to do it recursively by checking if the current key is a hash and if yes call the current function again with refference to the sub hash.
Most of the printing seems to be OK but in... (1 Reply)
Hi there
I have a hash of hashes made up of the following data
bge0|100|half|10.36.100.21
bge1|1000|full|10.36.100.22
bge2|1000|full|10.36.100.23
which when i turn into a hash, would look like this inside the system
bge0 ->
nic_speed -> 100
nic_duplex -> half
... (6 Replies)
Hi, sorry, two hash related questions in one day .. but this has got me a bit stuck.
I have a mysql database table that kind of looks like this, the table is called "view1" and a snippet of that table (SELECT'ing just rows with serial number 0629AN1200) is below
serial nic_name ... (2 Replies)
Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below.
#!/usr/bin/perl
use warnings;
use Tie::IxHash;
use strict;
tie (my %programs, "Tie::IxHash");
while (my $line = <DATA>) {
chomp $line;
my(... (1 Reply)
#use perl 5.8.5;
my %h1=(a=>'b', c=>'d');
my %h2=(a1=>'b1', c1=>'d1');
my $R1=\%h1;
my $R2=\%h2;
my %h= {$R1, $R2};
my $href=\%h; # hash of hashes
foreach my $key (keys %$href){
print "Z::$$href{$key}\n"
}
When I am trying to print elements of hash of hashes,
it prints HASH... (1 Reply)
Hi there, I am trying to dereference my hash of hashes but post dereferencing, it seems to lose its structure I am using Data::dumper to help me anaylise.
This is the code im using to build the HoH, (data comes from a file). I have also performed a Dumper on the data structure before and after... (1 Reply)
Hi,
I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all .
my %result (
$abc => {
'data_count' => '10',
'ID' => 'ABC122',
}
$def => {
'data_count' => '20',
'ID' => 'defASe',
... (1 Reply)
I have found this excellent site: NSRL Downloads
(sorry if it was already mentioned)
there are Solaris and Linux files there too.
its all in a text file, over 11Gb large. (0 Replies)
Hello experts. I'm having problems with a snippet of code.
I was hoping to get help/advice to correct.
A file that this script parses has changed to the point where
I can no longer use a scalar, it looks as though I need to
create an array for a hash of hashes below.
The first output of... (1 Reply)
Discussion started by: timj123
1 Replies
LEARN ABOUT DEBIAN
data::printer::filter::db
Data::Printer::Filter::DB(3pm) User Contributed Perl Documentation Data::Printer::Filter::DB(3pm)NAME
Data::Printer::Filter::DB - pretty printing database objects
SYNOPSIS
In your program:
use Data::Printer filters => {
-external => [ 'DB' ],
};
or, in your ".dataprinter" file:
{
filters => {
-external => [ 'DB' ],
};
DESCRIPTION
This is a filter plugin for Data::Printer. It filters through DBI's handlers (dbh) and statement (sth) objects displaying relevant
information for the user.
DBI is an extremely powerful and complete database interface. But it does a lot of magic under the hood, making their objects somewhat
harder to debug. This filter aims to fix that :)
For instance, say you want to debug something like this:
use DBI;
my $dbh = DBI->connect('dbi:DBM(RaiseError=1):', undef, undef );
A regular Data::Dumper output gives you absolutely nothing:
$VAR1 = bless( {}, 'DBI::db' );
Data::Printer makes it better, but only to debug the class itself, not helpful at all to see its contents and debug your own code:
DBI::db {
Parents DBI::common
Linear @ISA DBI::db, DBI::common
public methods(48) : begin_work, clone, column_info, commit, connected, data_sources, disconnect, do, foreign_key_info, get_info, last_insert_id, ping, prepare, prepare_cached, preparse, primary_key, primary_key_info, quote, quote_identifier, rollback, rows, selectall_arrayref, selectall_hashref, selectcol_arrayref, selectrow_array, selectrow_arrayref, selectrow_hashref, sqlite_backup_from_file, sqlite_backup_to_file, sqlite_busy_timeout, sqlite_collation_needed, sqlite_commit_hook, sqlite_create_aggregate, sqlite_create_collation, sqlite_create_function, sqlite_enable_load_extension, sqlite_last_insert_rowid, sqlite_progress_handler, sqlite_register_fts3_perl_tokenizer, sqlite_rollback_hook, sqlite_set_authorizer, sqlite_update_hook, statistics_info, table_info, tables, take_imp_data, type_info, type_info_all
private methods(0)
internals: {
}
}
Fear no more! If you use this filter, here's what you'll see:
SQLite Database Handle (connected) {
dbname: file.db
Auto Commit: 1
Statement Handles: 0
Last Statement: -
}
Much better, huh? :)
Statement handlers are even better. Imagine you continued your code with something like:
my $sth = $dbh->prepare('SELECT * FROM foo WHERE bar = ?');
$sth->execute(42);
With this filter, instead of an empty dump or full method information, you'll get exactly what you came for:
SELECT * FROM foo WHERE bar = ? (42)
Note that if your driver does not support holding of parameter values, you'll get a "bindings unavailable" message instead of the bound
values.
SEE ALSO
Data::Printer
perl v5.14.2 2011-05-30 Data::Printer::Filter::DB(3pm)