I just installed Text::CSV, my code is below, and here is my error:
Can't call method "getline" without a package or object reference at C:/Perl/site/lib/Text/CSV_XS.pm line 555, <FILE> line 2.
This might seem trivial, but I can't find the answer when I google my error.
I have also tried, use Text::CSV & Text::CSV->new
and still had the same error.
#!C:\Perl\bin\perl
use warnings;
use strict;
use Text::CSV_XS;
my $file = "file.csv";
open FILE, $file or die "cannot open file\n";
my $first = <FILE>;
my @columns = split(",", $first);
my $csv = Text::CSV_XS->new ( { binary => 1 } ) or die "Cannot use CSV
+: ".Text::CSV->error_diag ();
$csv->column_names(@columns);
my $lineNum = 1;
while (my $line = <FILE>) {
my $hr = $csv->getline_hr($line);
my $sku = $hr->{ 'sku' };
print "$sku\n";
$lineNum++;
}
close FILE
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.