> Any formating suggestions how this can be done?

Using Data::Dumper and then trying to reformat its output shows a bad case of cargo-cult coding. Don't do that.

My suggestion is that you learn how to use references. Right now, you are using Data::Dumper to do the extraction for you - this is the part of it that you want - but you don't want the output formatted the way that Data::Dumper does it. The answer is to step away from the whole mess and do it right: extract the references, dereference them to the actual underlying data structure (an array, in the case of 'fetchall_arrayref'), and print out the elements of that array in the way you want them.

You also need to read the DBI documentation and figure out which fetch method you want to use in order to get the information you want. If you want both the field names and the field values - as you imply - then perhaps 'fetchrow_hashref' would serve you better.

You should also learn how to use the 'printf' command to format your output. Very basic example of code - something you can expand and rework to suit your purposes, not blindly copy - follows:

#!/usr/bin/perl -w # use strict; use DBI; $|++; # Create the variables that will be loaded from '.dbinfo' our ($db, $table, $user, $pass, $query); # Load them up do ".dbinfo" or die "Database info not found!\n"; my $dbh = DBI->connect("DBI:mysql:$db", $user, $pass); my $sth = $dbh->prepare("select $query from $table"); $sth->execute; while (my $hash_ref = $sth->fetchrow_hashref){ for my $key (keys %$hash_ref){ printf "%-10s: %s\n", $key, $hash_ref->{$key}; } }

-- 
Human history becomes more and more a race between education and catastrophe. -- HG Wells

In reply to Re: Formatting question?? by oko1
in thread Formatting question?? by sudip_dg77

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.