Hi
ravi45722,
Please post the code that you are actually running. If I run your script, I get this output:
Can't locate method setDelimiter at rb.pl line 8.
The documentation for
Text::CSV states that this is how one defines the delimiter,
my $csv = Text::CSV->new({ sep_char => '|' });
So, here is a slightly modified version of your script.
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $csv = Text::CSV->new({ sep_char => '|' }); # create a new object
my $sample_input_string = '""|""|""|""|""|""|""|""|Submit|""|""|""|GSM
+|GSM|';
if ($csv->parse($sample_input_string)) {
my @field = $csv->fields;
my $count = 0;
for my $column (@field)
{
print ++$count, " => ", $column, "\n";
}
print "\n";
} else {
my $err = $csv->error_input;
print "parse() failed on argument: ", $err, "\n";
}
The output is:
1 =>
2 =>
3 =>
4 =>
5 =>
6 =>
7 =>
8 =>
9 => Submit
10 =>
11 =>
12 =>
13 => GSM
14 => GSM
15 =>
I'm not sure why you expect your output to be:
Submit|GSM|GSM => 560
as that does not seem consistent with your script or your input data.