Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You cannot simply store an object, where a string is expected.</p> <p>If we have an object <code>$o</code> of class <code>Emp</code>, and assuming that this object is implemented using hashes, than the <em>stringification</em> of that object would be something like <code>Emp=HASH(0x9bc8880)</code>. The information included in this stringification does not allow the restoration of the object from this string.</p> <p>Instead, you have to choose a serialization of the object, so that you can restore the object.</p> <p>The <a href="https://metacpan.org/module/Data%3a%3aDumper" rel="nofollow"><code>Data::Dumper</code> module</a> serializes data structures as Perl code, that can be <code>eval</code>ed to recreate the original value. The <a href="https://metacpan.org/module/Storable" rel="nofollow"><code>Storable</code> module</a> stores the data in a binary format, and might be applicable here.</p> <p>You can serialize a data structure (or object) via <code>freeze</code>, and restore it via <code>thaw</code>.</p> <pre><code>use strict; use warnings; use Storable qw(freeze thaw); use Data::Dumper; my $o = bless {a =&gt; 1, b =&gt; 2}, 'Emp'; print "&gt; Dumper representation of original ($o)\n"; print Dumper $o; print "&gt; serializing the object...\n"; my $serialized = freeze($o); print "&gt; restoring the object...\n"; my $restored = thaw($serialized); print "&gt; Dumper representation of copy ($restored)\n"; print Dumper $restored; </code></pre> <p>Output:</p> <pre><code>&gt; Dumper representation of original (Emp=HASH(0x8de78c8)) $VAR1 = bless( { 'a' =&gt; 1, 'b' =&gt; 2 }, 'Emp' ); &gt; serializing the object... &gt; restoring the object... &gt; Dumper representation of copy (Emp=HASH(0x8f5df64)) $VAR1 = bless( { 'a' =&gt; 1, 'b' =&gt; 2 }, 'Emp' ); </code></pre> <p>or similiar. Note that the restored object has a different memory location, but is equivalent otherwise.</p> <p>If you want to serialize a data structure to a file, you can use <code>store</code> and <code>retrieve</code> instead; consult the documentation for further examples.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload