Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

DBIx::Dump error - can't use string as subroutine ref

by sparkylu (Monk)
on Mar 26, 2007 at 22:09 UTC ( [id://606671]=perlquestion: print w/replies, xml ) Need Help??

sparkylu has asked for the wisdom of the Perl Monks concerning the following question:

Salutations Monks!

I am running the following code on WIN 2000 server to connect to a DB that's running locally, however, i get the following error :

Software error: Can't use string ("") as a subroutine ref while "strict refs" in use at F:/Perl/site/lib/DBIx/Dump.pm line 149

Any help will be much appreciated ....

#!f:/Perl/bin/perl.exe use DBI; use CGI::Lite; use CGI::Carp qw(fatalsToBrowser); use DBIx::Dump; my %data = $cgi->parse_form_data; ##read values that are passed #print distinct values of values of a db. #if values are not passed end... else call the subroutine -> display_d +ata() sub display_data { ##Write to Excel ## my $sth = $dbh->prepare("SELECT devicename,cadb,substatus,dns,ping,snm +p,dsiname,ovpi_st,sat,nnm,fqdn FROM consolidated_data where cadb like + '$cadb_pass' and substatus like '$substatus_pass' and dns like '$dn +s_pass' and ping like '$ping_pass' and snmp like '$snmp_pass' and ovp +i_st like '$ovpi_st_pass' and sat like '$sat_pass' and nnm like '$nnm +_pass' ORDER BY rowid"); $sth->execute() or die "Cannot execute sth: $DBI::errstr"; my $out = DBIx::Dump->new('format' => $format_pass, 'output' => $filename_pass, 'sth' => $sth); $out->dump( ); $sth->finish(); ###This above code works when used as stand alone code### #run the same query { print the results } $sth->finish(); $dbh->disconnect(); }
Update: changed the title

Replies are listed 'Best First'.
Re: DBIx::Dump error
by mreece (Friar) on Mar 26, 2007 at 22:49 UTC
    my $out = DBIx::Dump->new('format' => $format_pass, ...
    i think you will find that $format_pass does not eq one of 'excel', 'csv', or 'iQuery'.
    if ($format_pass eq "csv") {$filename_pass.=csv;}else {$filename_pass. +=xls;} if (!$filename_pass) {$filename_pass=query.csv;}
    you appear to be using bareword strings here, which is very dangerous and bound to bite you at some point. (ie, query.csv is being interpretted as "query"."csv" aka "querycsv" which is possible not what you inteded.)


    update: you should consider use strict; to help deal with the bareword issue mentioned above.

    i see you have a <select> being printed like so:

    <select type="option" name="format"><option>csv<option>xls</select>
    according to the docs, you want format => 'excel', not xls.
      Thank you so much ....

      I forgot to change the $format_pass to excel when xls was selected... That solved the problem ;D

      Can't thank you enough ... it's 4:45 am .. i needed to get back to office by 10am and i was unable to sleep till this got fixed... Thank you ... and Thank You again ;) U Da Man !!!

      Thank you ... I will give that a try and let you know the results.
Re: DBIx::Dump error
by GrandFather (Saint) on Mar 26, 2007 at 22:32 UTC

    Perhaps the best advice is to trim your sample code down to about 10 lines that demonstrate the problem. Over 300 lines of code, mostly completely irrelevant to the issue, is not a sussccint distillation of the problem.

    Most likely you have a variable that is not the reference you think it is. Check perlref. It may help to read I know what I mean. Why don't you? while you are at it.


    DWIM is Perl's answer to Gödel
Re: DBIx::Dump error
by saintly (Scribe) on Mar 26, 2007 at 22:56 UTC
    Although I'm shooting in the dark here (it would help to know the version of DBIx::Dump that you have, and the values of the CGI parameters), it looks like your variable

    $format_pass

    Is probably not one of the recognized formats that DBIx::Dump will print in. Perhaps you can hard-code it to 'excel' or 'csv' and see if that solves the problem.

    P00py, looks like mreece beat me to this one. =) Well, it wouldn't hurt if the author of DBIx::Dump did some validation on their input. The 'problem line' 149 in Dump.pm is:
    $formats{$self->{'format'}}->($self);
    So it's just attempting to exec a function associated with the 'format' query you provide, but it doesn't check to see if it's a valid function first. The CPAN docs don't say what functions are valid, but on lines 137-141 of Dump.pm you can see:
    my %formats = ( 'excel' => $excel, 'csv' => $csv, 'iQuery' => $iQuery );
    Which shows you the valid strings it will take as formats.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://606671]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-10-07 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (44 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.