use strict;
use warnings;
use Data::Dumper;
my @data_array = (
[qw/14 27 999 999 0 0/],
[qw/14 27 999 999 0 0/],
[qw/14 27 999 999 0 0/],
[qw/14 27 999 999 1 0/],
[qw/14 27 999 999 0 0/],
[qw/14 27 999 999 0 0/],
[qw/14 27 999 999 0 0/],
[qw/27 14 999 999 0 0/],
[qw/20 32 999 999 0 0/],
[qw/20 32 999 999 0 0/],
[qw/20 32 999 999 0 0/],
[qw/20 32 999 999 1 0/],
[qw/20 32 999 999 0 0/],
[qw/20 32 999 999 0 0/],
[qw/20 32 999 999 0 0/]
);
my @array = map { $_->[4] ? () : join(' ', sort @{$_}[0,1]) } @data_ar
+ray;
my %freq;
$freq{$_}++ for @array;
my @final = map { "$_ $freq{$_}" } keys %freq;
print Dumper(\@final);
#! /usr/bin/perl
use strict;
use Win32::Semaphore;
use Win32::MMF::Shareable;
$|++;
my $delay = 0.01;
my $i = 0;
if( fork )
{
my %share;
my $ns = tie( %share, 'Win32::MMF::Shareable', 'share' ) || die;
print $ns->namespace()->{_view}, "\n";
my $sem = Win32::Semaphore->new(1,1,'sig');
select( undef, undef, undef, $delay / 2 );
while( $i < 20 )
{
$sem->wait;
$share{ 'P' . $i++ } = '-';
# $ns->lock();
print "parent($i): " . join( '', values( %share ) ) . "\n";
# $ns->unlock();
$sem->release();
select( undef, undef, undef, $delay );
}
}
else
{
my %share;
my $ns = tie( %share, 'Win32::MMF::Shareable', 'share' ) || die;
print $ns->namespace()->{_view}, "\n";
my $sem = Win32::Semaphore->new(1,1,'sig');
while( $i < 20 )
{
$sem->wait;
$share{ 'P' . $i++ } = '#';
# $ns->lock();
print "child($i) : " . join( '', values( %share ) ) . "\n";
# $ns->unlock();
$sem->release();
select( undef, undef, undef, $delay );
}
}
use strict;
use warnings;
use Win32::MMF::Shareable;
# Tie variables to shared namespace
my $ns = 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';
for (1..1000) {
# as scalar
$shared = "Hello world";
# as list
@shared = ();
for (0..3) {
$shared[$_] = "$_" x ($_ + 1);
}
# as hash
%shared = @shared;
# iteration test
foreach (sort keys %sh2) {
my $n = $sh2{$_};
}
foreach (sort values %sh2) {
my $n = $_;
}
# hash slice test
my @keys = keys %sh2;
my @values = (0 .. $#keys);
@sh2{@keys} = @values;
}
__OUTPUT__
Total Elapsed Time = 1.955772 Seconds
User+System Time = 1.706772 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
100. 1.717 1.717 8000 0.0002 0.0002 Storable::mstore
18.2 0.311 0.311 18000 0.0000 0.0000 Storable::mretrieve
9.55 0.163 0.229 23006 0.0000 0.0000 Win32::MMF::lock
8.67 0.148 0.000 18000 0.0000 0.0000 Storable::thaw
8.61 0.147 2.420 9000 0.0000 0.0003 Win32::MMF::Shareable::ST
+ORE
8.20 0.140 0.554 8000 0.0000 0.0001 Win32::MMF::Shareable::FE
+TCH
8.14 0.139 0.000 8000 0.0000 0.0000 Storable::_freeze
7.85 0.134 0.673 21000 0.0000 0.0000 Win32::MMF::getvar
6.21 0.106 0.106 23006 0.0000 0.0000 Win32::MMF::ReleaseSemaph
+ore
4.45 0.076 0.243 3000 0.0000 0.0001 Win32::MMF::Shareable::FI
+RSTKEY
3.87 0.066 0.066 23006 0.0000 0.0000 Win32::MMF::WaitForSingle
+Object
3.22 0.055 1.979 11003 0.0000 0.0002 Win32::MMF::setvar
3.16 0.054 0.054 6000 0.0000 0.0000 Win32::MMF::Shareable::NE
+XTKEY
2.58 0.044 0.044 18999 0.0000 0.0000 Win32::MMF::GetVar
2.58 0.044 0.083 2000 0.0000 0.0000 Win32::MMF::Shareable::CL
+EAR
The PPM install guide...
http://www.perlmonks.org/?node_id=434813
|