Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-09-26 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (117 votes). Check out past polls.

    Notices?