in reply to Printing Array with quote and comma

Or just use the existing functionality provided by Data::Dumper:

use Data::Dumper; $Data::Dumper::Indent = 0; my @arr = qw(book dog cat); print Dumper(\@arr);

If you want to do your way, then fix those ' and ":

my @arr = qw(book dog cat); print "[" . join(',', @arr) . "];\n";

Replies are listed 'Best First'.
Re^2: Printing Array with quote and comma
by davido (Cardinal) on Oct 05, 2005 at 04:01 UTC

    As long as we're doing down the "other ways to do it" road...

    my @arr = qw(book dog cat); { local $" = "','"; print "['@arr'];\n"; }

    And if that one's not ugly enough, we can certanly take it down that path too...

    my @arr = qw(book dog cat); $"='\',\'';print"['@arr'];$/";

    ...just having fun, of course.


    Dave