Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Export CSV v2

by GrandFather (Sage)
on Oct 09, 2012 at 00:23 UTC ( #997902=note: print w/replies, xml ) Need Help??


in reply to Re^2: Export CSV v2
in thread Export CSV v2

Try adding:

$csv->eol ("\x0d\x0a");

after the my $csv = Text::CSV_XS->new ... statement. Probably Excel is generating Windows line ends even on a Mac and Perl is expecting either *nix of (legacy) Mac line endings.

True laziness is hard work

Replies are listed 'Best First'.
Re^4: Export CSV v2
by Tux (Abbot) on Oct 09, 2012 at 07:00 UTC

    Don't! Text::CSV_XS and Text::CSV both dynamically support \r \x0D, \n \x0A, or \r\n \x0D\x0A even if they change per line if eol is not specified.

    You might want to do so on output though:

    print "Writing to file: $ofile_name\n"; $templateTextCopy =~ s{(?: \r\n | \r | \n )} {\r\n}gx; # <-- make line ending consis +tent open my $fh, ">", $ofile_name or die "$ofile_name: $!"; print $fh $templateTextCopy; close $fh;

    Enjoy, Have FUN! H.Merijn
Re^4: Export CSV v2
by Perl3r (Initiate) on Oct 09, 2012 at 00:41 UTC

    Ok I have the script as follows:

    my $csv = Text::CSV->new( { binary => 1, auto_diag => 2, } ) or die "Cannot use CSV: " . Text::CSV->error_diag(); $csv->eol ("\x0d\x0a"); for my $csvFile (@ARGV) { print "\nProcesing file $csvFile ...\n"; open my $csvfh, '<', $csvFile or die "Unable to open $csvFile: $!" +;

    When I run the script, i still get the following error:

    Can't use an undefined value as an ARRAY reference at test.pl line 23, <$csvfh> line 1.

    This happens whether the CSV is in MS Excel format, or TXT

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997902]
help
Chatterbox?
[tye]: that is what getlogin() certainly *used* to do. I don't believe that is what it certainly should do.
[davido]: /var/run/utmp is 664 i think.
[tye]: Note that my "man getlogin" says that it uses stdin when it should use /dev/tty (calling a glibc bug). But that does not appear to be the case when I test it. But maybe Perl's getlogin() is not using glibc's getlogin().
[oiskuu]: well, run a strace and see what the getlogin does for you.... As I said. SELinux probably has those security labels. But not regular linux.
[tye]: for example, read https://unix. stackexchange.com/ questions/146138/ loginuid-should-be -allowed-to-change -or-not-mutable-or -not
[tye]: I'm not using SELinux and it certainly appears to disagree with you. shrug
[tye]: Since you brought up /proc, oiskuu, I didn't see you respond to my suggestion of 'loginuid'. Does your /proc not have such?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2017-06-23 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (554 votes). Check out past polls.