#!perl -w use strict; use Data::Dumper; my %addrRow = ( 'name' => 'Billy', 'email' => 'billy@email.com', 'city' => 'NY', 'country' => 'USA' ); $Data::Dumper::Indent = 0; $Data::Dumper::Purity = 1; my $scalar = Data::Dumper->Dump( [\%addrRow], ['*addrRow'] );

$scalar now contains the hash. You can print() the value to see the hash, print the value to a file and later do() the file to recreate the hash, or use an eval() on the scalar... You can do quite a bit :) Sadly, I used to use this as a database, until I found out that the pages load quite slowly when multiple requests are waiting for the release of a sequentially locked file while Data::Dumper does its job. Now I use MySQL for nearly everything.

Update: Just to add something so I don't get yelled at :) If you do indeed use Data::Dumper to save the hash to a file and then use do() to recreate the hash, you should most likely lock a sequential file to prevent damage to the data. Also, if you 'use strict' (which you should be), you will have to declare the hash via our() or use vars() before do()ing the file. Otherwise, strict will complain, etc etc.

-------------------------------------
eval reverse@{[lreP
=>q{ tsuJ\{qq},' rehtonA'
,q{\}rekcaH },' tnirp']}[1+1+
1,1-1,1+1,1*1,(1+1)*(1+1)];
-------------------------------------

In reply to Re: print hash into scalar by mt2k
in thread print hash into scalar by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.