Perl: Print Array or Hashtable
Print Array or Hashtable
if you want to print array or hashtable for later reading into Perl program, you'll need to use module Data::Dumper
.
use utf8; use Data::Dumper; $Data::Dumper::Indent = 0; # set it to print in a compact way @ss = (3, 4, 5); %ss = qw(mary 17 joe 18 alice 19); # qw for autoquote, same as ('mary' => 17, 'joe' => 18, 'alice' => 19) print Dumper(\@ss), "\n"; # $VAR1 = [3,4,5]; print Dumper(\%ss), "\n"; # $VAR1 = {'alice' => '19','joe' => '18','mary' => '17'};
The backslash in front of array variable is necessary. It returns the “reference” of the array, and the argument to Dumper must be a reference.