#!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)];
-------------------------------------
-
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 How to display code and escape characters
are good places to start.
|