Q:

Hash to CSV/TSV conversion in Perl

I'm trying to convert a simple hash to CSV/TSV in Perl. Now, the tricky part is that I'm unable to use Text::CSV::Slurp due to some funny reason, and I'm left with using Text::CSV_XS and Text::CVS. 
Problem Description: 
I am able to create a CSV file from the hash that I have, but display of the values isn't how I would desire them to be. 
Example: 
This is how my hash looks like: 
`$VAR1 = {
          '2015-12-09 10:49:00' => '750 mW',
          '2015-12-09 10:49:02' => '751 mW'
        };`

I would want keys to be under one tab and values to be under another tab. Instead, I get a CVS which has everything in a comma-separated state. 
Desired Output: 
key1   value1
key2   value2 

Actual Output: 
key1  value1   key2   value2 

This is how my code looks like as of now: 
open(DATA, "+>file.csv") || die "Couldn't open file file.csv, $!";
my $csv = Text::CSV_XS->new();
if ($input == 19){ 
    my $status = $csv->print (\*DATA, \@{[%hash1]});
}
elsif ($input == 11){
    my $status = $csv->print (\*DATA, \@{[%hash2]});
}
close(DATA) || die "Couldn't close file properly";

I have went through numerous questions in Stack Overflow and Perl Monks, but I somehow haven't been able to figure out the solution to this without using Text::CSV::Slurp. 
Please help. 
P.S: %hash1 and %hash2 are simple hashes which have basic key-value pairing, and are not hash of hashes as of now. However, as the code develops, I may have to implement the logic on HoH as well. 

A:

If I'm reading you right, something like this is what you're after:
#!/usr/bin/env perl
use strict;
use warnings;

use Text::CSV;

my $VAR1 = {
          '2015-12-09 10:49:00' => '750 mW',
          '2015-12-09 10:49:02' => '751 mW'
        };
        
my $csv = Text::CSV -> new ( { sep_char => "\t", eol => "\n", binary => 1 } );
foreach my $key ( sort keys %{$VAR1} )  {
    $csv -> print ( \*STDOUT, [ $key, $VAR1 -> {$key} ] );
}

(Or if you're doing it with a hash, not hash ref):
foreach my $key ( sort keys %hash ) { 
     $csv -> print ( \*STDOUT, [ $key, $hash{$key} ] );
}

Note - this is explicitly sorting, because hashes are unordered. You look to be using an sortable date format, so this should be ok, but you may need to parse a data to an epoch and parse based on that.
Output
"2015-12-09 10:49:00"   "750 mW"
"2015-12-09 10:49:02"   "751 mW"

Note - TSV embeds quotes because the fields contain spaces. You can remove those by:
my $csv = Text::CSV -> new ( { sep_char => "\t", 
                               eol => "\n", 
                               binary => 1, 
                               quote_char => undef } );

I would strongly suggest not using DATA as your output filehandle, as it's used already in perl. In fact, I would suggest using lexical filehandles with 3 arg open:
open ( my $output, '>', 'file.csv' ) or die $!;

# ...

$csv -> print ( $output, ### everything else

