1

I tried to print an array to a csv file, and to do this write this code:

use strict;
use warnings;

use Text::CSV;

use Text::CSV_XS;

my $csv = Text::CSV_XS->new();

my $file = "data.csv";

open(OUT, '<', $file) or die "Could not open '$file' $!\n";

my @columns = (qw/what ever the items are for each columns/);

my $status = $csv->print(OUT, \@columns);

And this script return me this: Bareword "OUT" not allowed while "strict subs" in use at test.pl line 37. Execution of test.pl aborted due to compilation errors.

I try to use Text::CSV or Text::CSV_XS to print data in csv and i need more information about syntax.

0

1 Answer 1

3

You can't use bareword filehandles as subroutine parameters. Use lexical filehandles instead:

open my $out, '<', $file or die ...;
$csv->print($out, \@columns);

Or, use the typeglob sigil (less preferable):

$csv->print(*OUT, \@columns);

Moreover, you opened the file for reading (<). You can't print to an input filehandle. Did you mean >?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.