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

I'm having trouble with this simple script, it's not running it gives me an error Can't locate object method "getline" via package "IO::Handle" at update.cgi line 10

What I'm doing wrong here...

#!/usr/bin/perl # -------------------------------------------- print "Content-type: text/html\n" ; print "Pragma: no-cache\n\n"; use Text::CSV_XS; $id = "832333"; $in{'p_address_2'} = "Test 123"; my $fh = Text::CSV_XS->new({ binary => 1, sep_char => '|', eol => "\n" +}); open my $csv, "<", "./Admin/data/bims-properties.db" or die "./Admin/d +ata/bims-properties.db: $!"; while (my $row = $csv->getline($fh)) { if ($row->[0] eq $id) { $row->[8] = $in{'p_address_2'}; print qq~ $row->[8]~; } $csv->print($out, $row); } close $fh or die "./Admin/data/bims-properties.db: $!"; print qq~ end~; exit;

Replies are listed 'Best First'.
Re: FLAT FILE Pipedemimited
by Anonymous Monk on Jul 24, 2014 at 00:33 UTC

     What I'm doing wrong here...

    You've named your variables poorly, the Text::CSV_XS object which has a getline method is called $fh, whereas your filehandle is called $csv

Re: FLAT FILE Pipedemimited
by GotToBTru (Prior) on Jul 24, 2014 at 20:11 UTC

    You've got $fh and $csv reversed in your statement.

    while (my $row = $csv->getline($fh)) {

    should be

    while (my $row = $fh->getline($csv)) {

    $fh is the object with a getline method. It takes the file handle as an argument.

    1 Peter 4:10