Hi Monks, I have two files like below. 1st file : mail.pl
#!/usr/bin/perl use DBD::mysql; use DBI; use Utils::DBClass; $object = new DBClass( "perltest", "localhost", 3306,"root", "sierra") +; $object -> select_db ("select * from samples");
2nd file DBClass.pm in a folder named Utils.
package DBClass; use DBI; @ISA = ('Exporter'); @EXPORT_OK = ("Connection_check", "new","select_db"); sub Connection_check { my($self ) = @_; $dsn = "DBI:mysql:database=$self->{_db};host=$self->{_host};port=$self +->{_port}"; $dbh = DBI->connect($dsn,$self->{_user},$self->{_pass}); return ($dbh) } sub new { my $class = shift; my $self = { _db => shift, _host => shift, _port => shift, _user => shift, _pass => shift }; $dbh = Connection_check($self); $self->{_dbh} = $dbh; bless $self, $class; return $self; } ### Retrieving the Rows ######## sub select_db{ my ($obj,$sel) = @_; my $sth1 = $dbh->prepare($sel); $sth1->execute or die "SQL Error: $DBI::errstr\n"; my @row; while (@row = $sth1->fetchrow_array) { print "@row \n"; } }
I am Getting the output for the quiries i mentioned above as below: <html> 1 Koti 555-5555 2 Siva 222-2222 3 Praneet 555-5555 4 nishitha 08649-257828 6 Anu 222-2222 7 Pradeep 555-5555 8 Asmit 222-2222 9 Surya 555-5555 </html> My requirement is getting the out put with out using the "print" statement in the select_db function. i want to get the ouput using "return" function and using "array of arrays". can anyone suggest me how to proceed .

In reply to Small Doubt Regarding Select Staement in DB by koti688

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.