#!/usr/bin/perl -w use strict; # Set up test data my @header = ( 'Name', 'DOB', 'DOJ', 'Country', 'Region', 'Salary', 'Place', ); my @data = ( 'JKSLK', 19890101, 20000101, 'France', 'ALMERIA', 100000.00, 'BCFGHK', ); my $empid = 123456; # Set up working data my @report = (); my @array = (); # Initialize push @array, @header; # Do the work my $csvfile; # SKM: What is this for, exactly? my $reportLine = join "\t", ($empid, @array); print "DEBUG: \$reportLine = [$reportLine]\n"; push @report,$reportLine,"\n"; foreach my $reportElement (@report) { print "DEBUG: \$reportElement = [$reportElement]\n"; } foreach (@report) { print $_; print $csvfile $_; } exit; __END__ #### C:\Steve\Dev\PerlMonks\P-2013-07-11@1436-CSV-Fail>perl csvfail2.pl DEBUG: $reportLine = [123456 Name DOB DOJ Country Region Salary Place] DEBUG: $reportElement = [123456 Name DOB DOJ Country Region Salary Place] DEBUG: $reportElement = [ ] Can't use an undefined value as a symbol reference at csvfail2.pl line 54. 123456 Name DOB DOJ Country Region Salary Place