Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: print hash into scalar

by mt2k (Hermit)
on Dec 23, 2002 at 08:28 UTC ( #221825=note: print w/replies, xml ) Need Help??

in reply to print hash into scalar

#!perl -w use strict; use Data::Dumper; my %addrRow = ( 'name' => 'Billy', 'email' => '', '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+

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://221825]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2022-08-16 12:47 GMT
Find Nodes?
    Voting Booth?

    No recent polls found