http://www.perlmonks.org?node_id=11108335

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

Hi,

I'm going to modify a perl script which opens a write connection to a Postgresql DB, in this way:

open(DATA_FILE,"<:utf8",$filename) || die print "can not open reading +file --> \"$filename\""; open DB, '| /opt/postgresql-9.4/bin/psql -h ... (here all the paramete +rs)' print DB "copy $table($header) from STDIN CSV;\n"; while ( my $line = <DATA_FILE>) { print DB "$line"; }

Well, I need to configure the DB connection encoding as UTF8, and I already did it successfully for the above open DATA_FILE, but now I'm wondering how to specify the ":utf8" in the "open DB...".

I tried the following one:

open(DB, ">:utf8", '| /opt/postgresql-9.4/bin/psql -h ... ')

but it does not work.

Then I tried:

open(DB, "+>:utf8", '| /opt/postgresql-9.4/bin/psql -h ... ')

still not working.

Any help?

I suppose it fails because of that EXPR parameter ('| /opt/...') which contains a pipe and it is not exactly an expression...

Best,
Lorenzo

Update: 5 Nov 19, footpad: Added HTML formatting tags, per Consideration.