in reply to DBI fetchall_hashref convert to scalar
Because a hash reference is already a scalar, I'm assuming that you mean you want it into a scalar *string*. Here's one way that you can exploit a scalar reference to be used as a memory file, and write the output of Data::Dumper directly to that scalar as a string value.
use warnings; use strict; use Data::Dumper; my $href = { a => 1, b => [ 2, 3, ], c => { 25 => 'y', 26 => 'z', }, d => 4, }; my $memfile; open my $mfh, '>', \$memfile or die $!; print $mfh Dumper($href); close $mfh; print $memfile;
Output:
$VAR1 = { 'c' => { '25' => 'y', '26' => 'z' }, 'b' => [ 2, 3 ], 'd' => 4, 'a' => 1 };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DBI fetchall_hashref convert to scalar
by hippo (Archbishop) on Feb 03, 2017 at 09:52 UTC | |
|
Re^2: DBI fetchall_hashref convert to scalar
by huck (Prior) on Feb 03, 2017 at 00:18 UTC | |
by stevieb (Canon) on Feb 03, 2017 at 00:21 UTC | |
by huck (Prior) on Feb 03, 2017 at 00:52 UTC | |
by stevieb (Canon) on Feb 03, 2017 at 00:58 UTC |