Hi
xiper, thanks for the positive feedback and excellent suggestions!
I have added the tie() interface to my module and released version 0.05 to CPAN, plus I have fixed a bug with MMF memory allocation and recycling, and fixed a bug with variable deletion.
The following is what you can do with the new version:
- Everything you can do with version 0.04, plus ...
use strict;
use warnings;
use Data::Dumper;
use Win32::MMF::Shareable qw/Debug/;
# Must initialize namespace before use
Win32::MMF::Shareable::Init( -namespace => 'MySharedmem' );
# Tie variables to shared namespace
tie my $shared, "Win32::MMF::Shareable", '$shared';
tie my @shared, "Win32::MMF::Shareable", '@shared';
tie my %shared, "Win32::MMF::Shareable", '%shared';
tie my $sh2, "Win32::MMF::Shareable", '$shared';
tie my @sh2, "Win32::MMF::Shareable", '@shared';
tie my %sh2, "Win32::MMF::Shareable", '%shared';
# as scalar
$shared = "Hello world";
# as list
@shared = ();
for (0..3) {
$shared[$_] = "$_" x ($_ + 1);
}
# as hash
%shared = @shared;
Debug();
print Dumper(\@sh2), "\n";
print Dumper(\%sh2), "\n";
print Dumper(\$sh2), "\n";
# iteration test
foreach (sort keys %sh2) {
print "$_ => $sh2{$_}\n";
}
foreach (sort values %sh2) {
print "$_\n";
}
# hash slice test
my @keys = keys %sh2;
my @values = (0 .. $#keys);
@sh2{@keys} = @values;
print Dumper(\%sh2);
:-)
-
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.