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

FLAT FILE Pipedemimited

by itmajors (Initiate)
on Jul 24, 2014 at 00:09 UTC ( [id://1094863]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found