in reply to Re^3: Help with converting Python script to Perl for CSV sort
in thread Help with converting Python script to Perl for CSV sort

This is helping me a great deal; however, I am now confused at another step. When I run the above code you provided - I get the following output.

__DATA___ E:\code\perl>cli-pl-csvProcess.pl a.cs $VAR1 = [ [ '7', 'Ace hardware', 'Ace hardware1' ], [ '4', 'Acme cook book', 'Acme cook book1' ], [ '10', 'Attack show', 'Attack show1' ], [ '8', 'Baker\'s dozon', 'Baker\'s dozon1' ], [ '1', 'Beginning C', 'Beginning C1' ], [ '2', 'Beginning C++', 'Beginning C++1' ], [ '9', 'Jumbo frames', 'Jumbo frames1' ], [ '5', 'Jumping Jack Flash', 'Jumping Jack Flash1' ], [ '3', 'Python Intro', 'Python Intro1' ], [ '6', 'Zebra', 'Zebra1' ], [ '11', 'car 54 where are you', 'car 54 where are you1' ], [ '12', 'navy blue', 'navy blue1' ], [ '13', 'navy gold', 'navy gold1' ] ];

How can I format this back into a normal CSV format output? My goal is to create a new file called output like in my hacked python script..

I can handle the file appending part; however, I do not full understand what is taking place right now. Looks like an Array of an array was printed out, but I am not sure if that is what I want or need.

Replies are listed 'Best First'.
Re^5: Help with converting Python script to Perl for CSV sort
by poj (Abbot) on Jan 31, 2017 at 18:56 UTC

    You are seeing the output of print Dumper \@sorted; which is a quick way of inspecting the contents of a data structure. Just replace that line with what you had originally.

    #print Dumper \@sorted; open my $fh_out,'>','output.csv' or die "$!"; foreach my $row ( @sorted ) { print $fh_out join( ',', @$row ), "\n"; } close $fh_out;
    poj