[31737] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3000 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 23 03:09:25 2010

Date: Wed, 23 Jun 2010 00:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 23 Jun 2010     Volume: 11 Number: 3000

Today's topics:
    Re: DB_File (hash of array) problem <hslee911@yahoo.com>
    Re: DB_File (hash of array) problem <tadmc@seesig.invalid>
    Re: DB_File (hash of array) problem <xhoster@gmail.com>
    Re: DB_File (hash of array) problem <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: FAQ 9.15 How do I parse a mail header? <brian.d.foy@gmail.com>
    Re: FAQ 9.22 How do I read mail? <brian.d.foy@gmail.com>
    Re: How to use Regex to breakdown a pattern and use the sln@netherlands.com
        How to use Regex to breakdown a pattern and use the pat <gjwpp88@gmail.com>
    Re: How to use Regex to breakdown a pattern and use the <tadmc@seesig.invalid>
        Proposing a new module: Parallel::Loops <4ux6as402@sneakemail.com>
        UNIX datagram sockets <jak@isp2dial.com>
    Re: UNIX datagram sockets <uri@StemSystems.com>
    Re: UNIX datagram sockets <jak@isp2dial.com>
    Re: UNIX datagram sockets <uri@StemSystems.com>
        what cpu core is running the script? <fgnowfg@gmail.com>
    Re: what cpu core is running the script? <josef.moellers@ts.fujitsu.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 22 Jun 2010 12:43:05 -0700 (PDT)
From: James <hslee911@yahoo.com>
Subject: Re: DB_File (hash of array) problem
Message-Id: <48ee585e-a435-478a-8ebd-5f5f16a59542@j8g2000yqd.googlegroups.com>

On Jun 21, 10:45=A0pm, Xho Jingleheimerschmidt <xhos...@gmail.com>
wrote:
> James wrote:
> > I am trying to write to a database a hash of array (as seen by
> > __DATA__ in the code).
> > But somehow the first element of the array is missing. Any idea why?
>
> I don't believe DB_File supports nested data structures.
>
> > The second time, it is working correctly.
>
> > $ cat run.pl
> > use DB_File;
> > use vars qw($db $x %h $k $v $i $key $val);
>
> Ugg. =A0Scope variables to the smallest scope you can.
>
> You should use strict.
>
> You seem to be accidentally using symbolic references.
>
> The inner data never got stored in DB_File in the first place, it is
> only stored in Perl's memory.
>
> > =A0 =A0 =A0 =A0 for $i (0..$#v) {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $h{$k}->[$i] =3D $r->[$i];
> > =A0 =A0 =A0 =A0 }
>
> The first time through, an array is auto-vivified, and it contains
> $r->[0]. =A0When a reference to this array is stuffed into $h{$k}, it get=
s
> stringified to something like 'ARRAY(0x825c3dc)' because the tied hash
> only accepts strings, not array references. =A0At that point, the array
> and the string become disconnected from each other, and the value of
> that auto-vivified array, the copy of $r->[0], is lost.
>
> The second subsequent time, you are using a symbol reference to a
> variable with the peculiar name 'ARRAY(0x825c3dc)', into which you stuff
> the remaining values.
>
> > sub read_db {
> > print "=3D=3D=3D read $db =3D=3D=3D\n";
> > for ( $status =3D $x->seq($key, $val, R_FIRST); $status =3D=3D 0; $stat=
us =3D
> > $x->seq($key, $val, R_NEXT) )
> > {
> > =A0 =A0 =A0 =A0 print "$key -> @{$val}\n";
>
> At this point, you are pulling the values out of the peculiarly named
> variable using symbolic references.
>
> If you separate your program so the perl instance that reads the DB is
> not the same one that created it, you will find the values never got
> stored to the DB in the first place.
>
> Xho

Thanks for your reply. Where can I find a reference to your statement,

"because the tied hash only accepts strings, not array references."

Anyway, I've re-written the run.pl script and run twice, see below.
The second time, it looks as though the reference to an array seems
working, but I may be wrong.


$ cat run.pl
use strict vars;
use DB_File;
my ($db) =3D @ARGV;
my %h =3D ();
my $x =3D tie %h, "DB_File", $db, O_RDWR|O_CREAT, 0640, $DB_HASH;

print "=3D=3D=3D write $db =3D=3D=3D\n";
my $k;
my @v;
my $r;
for (<DATA>)
{
        @v =3D ();
        ($k, @v) =3D split;
        $r =3D \@v;
        for my $i (0..$#v)
        {
                $h{$k}->[$i] =3D $r->[$i];
                print "($k -> $i -> ", $h{$k}->[$i], ") ";
        }
        print "\n";
}

print "=3D=3D=3D read $db =3D=3D=3D\n";
my $st;
my $key;
my $val;
my @val;
for ( $st =3D $x->seq($key, $val, R_FIRST); $st =3D=3D 0; $st =3D $x-
>seq($key, $val, R_NEXT) )
{
        @val =3D @{$val};
        for my $i (0..$#val) {
                print "($key -> $i -> $val[$i]) ";
        }
        print "\n";
}

untie %h;
undef $x;

__DATA__
aa 1 2 3
cc 678 99
zz foo fee fuu fun


$ rm testdb
$ ./run.pl testdb
=3D=3D=3D write testdb =3D=3D=3D
(aa -> 0 -> ) (aa -> 1 -> 2) (aa -> 2 -> 3)
(cc -> 0 -> ) (cc -> 1 -> 99)
(zz -> 0 -> ) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)
=3D=3D=3D read testdb =3D=3D=3D
(aa -> 0 -> ) (aa -> 1 -> 2) (aa -> 2 -> 3)
(cc -> 0 -> ) (cc -> 1 -> 99)
(zz -> 0 -> ) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)

$ ./run.pl testdb
=3D=3D=3D write testdb =3D=3D=3D
(aa -> 0 -> 1) (aa -> 1 -> 2) (aa -> 2 -> 3)
(cc -> 0 -> 678) (cc -> 1 -> 99)
(zz -> 0 -> foo) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)
=3D=3D=3D read testdb =3D=3D=3D
(aa -> 0 -> 1) (aa -> 1 -> 2) (aa -> 2 -> 3)
(cc -> 0 -> 678) (cc -> 1 -> 99)
(zz -> 0 -> foo) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)



JL


------------------------------

Date: Tue, 22 Jun 2010 16:50:22 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: DB_File (hash of array) problem
Message-Id: <slrni22bnk.agf.tadmc@tadbox.sbcglobal.net>

James <hslee911@yahoo.com> wrote:
> On Jun 21, 10:45 pm, Xho Jingleheimerschmidt <xhos...@gmail.com>
> wrote:
>> James wrote:

>> > use vars qw($db $x %h $k $v $i $key $val);
>>
>> Ugg.  Scope variables to the smallest scope you can.


> my $k;
> my @v;
> my $r;


You have not scoped those to the smallest scope you can.

They are "global" within this file.

If you are only going to use then in the for loop, then they
should be scoped to only the for loop. Lose the declarations
above and instead define each at its first use:

> for (<DATA>)
> {
>         @v = ();


That line doesn't do anything useful, as you are going to stomp
over @v in the next line anyway. Lose that line too.


>         ($k, @v) = split;

    my($k, @v) = split;

>         $r = \@v;

    my $r = \@v;


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: Tue, 22 Jun 2010 18:37:30 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: DB_File (hash of array) problem
Message-Id: <4c21650c$0$28517$ed362ca5@nr5-q3a.newsreader.com>

James wrote:
> 
> Thanks for your reply. Where can I find a reference to your statement,
> 
> "because the tied hash only accepts strings, not array references."

I don't have a reference, just empirical evidence.  (Use Data::Dumper
to dump your hash, and it shows stringified used-to-be-references.)

Also, DB_File is a Perl wrapper around a C library.  I would not expect 
a C library to support Perl nested structures, and if the Perl wrapper 
took great pains to emulate such support, it probably would have been 
mentioned.

> Anyway, I've re-written the run.pl script and run twice, see below.
> The second time, it looks as though the reference to an array seems
> working, but I may be wrong.

What you need to do is prevent the hash from getting created during one 
execution.  An easy way to do that is to wrap
if (@ARGV<=1) { ...}
around the part that populates (writes) the hash.  Then you can suppress 
the population of the hash by supplying an extra argument.

Or just break the populating and the reading into different scripts.


What you will find is that the nested parts of the hash are being 
written into Perl's memory, not onto disk.

> $ cat run.pl
> use strict vars;

The issue you are having is not covered by strict vars, but rather is 
covered by strict refs.


> $ rm testdb
> $ ./run.pl testdb
> === write testdb ===
> (aa -> 0 -> ) (aa -> 1 -> 2) (aa -> 2 -> 3)
> (cc -> 0 -> ) (cc -> 1 -> 99)
> (zz -> 0 -> ) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)
> === read testdb ===
> (aa -> 0 -> ) (aa -> 1 -> 2) (aa -> 2 -> 3)
> (cc -> 0 -> ) (cc -> 1 -> 99)
> (zz -> 0 -> ) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)

At this point, the strings that looks like references but aren't have 
been written to disk under DB_File.

> 
> $ ./run.pl testdb
> === write testdb ===
> (aa -> 0 -> 1) (aa -> 1 -> 2) (aa -> 2 -> 3)
> (cc -> 0 -> 678) (cc -> 1 -> 99)
> (zz -> 0 -> foo) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)

Here, the array is not autovivified, because the hash (being tied to 
previously populated disk file) already has entries, strings that look 
like references, but aren't.  So now the first value of each set is 
picked up and stuffed into the funnily named variables using symbolic 
references, rather than being lost as before.

> === read testdb ===
> (aa -> 0 -> 1) (aa -> 1 -> 2) (aa -> 2 -> 3)
> (cc -> 0 -> 678) (cc -> 1 -> 99)
> (zz -> 0 -> foo) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)

Now you are printing out the things you just stuffed into memory.

If you change the code so it just ties the hash and skips the "writing" 
part and goes right to read, you will find you get no output.

Xho


------------------------------

Date: Wed, 23 Jun 2010 00:42:58 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: DB_File (hash of array) problem
Message-Id: <3JadnY9WXe49ALzRnZ2dnUVZ_hKdnZ2d@earthlink.com>

On 06/22/2010 02:43 PM, James wrote:
> On Jun 21, 10:45 pm, Xho Jingleheimerschmidt <xhos...@gmail.com>
> wrote:
>> James wrote:
>>> I am trying to write to a database a hash of array (as seen by
>>> __DATA__ in the code).
>>> But somehow the first element of the array is missing. Any idea why?
>> I don't believe DB_File supports nested data structures.
>>
>>> The second time, it is working correctly.
>>> $ cat run.pl
>>> use DB_File;
>>> use vars qw($db $x %h $k $v $i $key $val);
>> Ugg.  Scope variables to the smallest scope you can.
>>
>> You should use strict.
>>
>> You seem to be accidentally using symbolic references.
>>
>> The inner data never got stored in DB_File in the first place, it is
>> only stored in Perl's memory.
>>
>>>         for $i (0..$#v) {
>>>                 $h{$k}->[$i] = $r->[$i];
>>>         }
>> The first time through, an array is auto-vivified, and it contains
>> $r->[0].  When a reference to this array is stuffed into $h{$k}, it gets
>> stringified to something like 'ARRAY(0x825c3dc)' because the tied hash
>> only accepts strings, not array references.  At that point, the array
>> and the string become disconnected from each other, and the value of
>> that auto-vivified array, the copy of $r->[0], is lost.
>>
>> The second subsequent time, you are using a symbol reference to a
>> variable with the peculiar name 'ARRAY(0x825c3dc)', into which you stuff
>> the remaining values.
>>
>>> sub read_db {
>>> print "=== read $db ===\n";
>>> for ( $status = $x->seq($key, $val, R_FIRST); $status == 0; $status =
>>> $x->seq($key, $val, R_NEXT) )
>>> {
>>>         print "$key -> @{$val}\n";
>> At this point, you are pulling the values out of the peculiarly named
>> variable using symbolic references.
>>
>> If you separate your program so the perl instance that reads the DB is
>> not the same one that created it, you will find the values never got
>> stored to the DB in the first place.
>>
>> Xho
> 
> Thanks for your reply. Where can I find a reference to your statement,
> 
> "because the tied hash only accepts strings, not array references."
> 
> Anyway, I've re-written the run.pl script and run twice, see below.
> The second time, it looks as though the reference to an array seems
> working, but I may be wrong.
> 
> 
> $ cat run.pl
> use strict vars;

As Xho said, if you were to use the other features of strict.pm, you 
would find out that you are unintentionally using strings as references.

> use DB_File;
> my ($db) = @ARGV;
> my %h = ();
> my $x = tie %h, "DB_File", $db, O_RDWR|O_CREAT, 0640, $DB_HASH;
> 
> print "=== write $db ===\n";
> my $k;
> my @v;
> my $r;
> for (<DATA>)
> {
>         @v = ();
>         ($k, @v) = split;
>         $r = \@v;
>         for my $i (0..$#v)
>         {
>                 $h{$k}->[$i] = $r->[$i];
>                 print "($k -> $i -> ", $h{$k}->[$i], ") ";
>         }
>         print "\n";
> }
> 
> print "=== read $db ===\n";
> my $st;
> my $key;
> my $val;
> my @val;
> for ( $st = $x->seq($key, $val, R_FIRST); $st == 0; $st = $x-
>> seq($key, $val, R_NEXT) )
> {
>         @val = @{$val};
>         for my $i (0..$#val) {
>                 print "($key -> $i -> $val[$i]) ";
>         }
>         print "\n";
> }
> 
> untie %h;
> undef $x;
> 
> __DATA__
> aa 1 2 3
> cc 678 99
> zz foo fee fuu fun
> 
> 
> $ rm testdb
> $ ./run.pl testdb
> === write testdb ===
> (aa -> 0 -> ) (aa -> 1 -> 2) (aa -> 2 -> 3)
> (cc -> 0 -> ) (cc -> 1 -> 99)
> (zz -> 0 -> ) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)
> === read testdb ===
> (aa -> 0 -> ) (aa -> 1 -> 2) (aa -> 2 -> 3)
> (cc -> 0 -> ) (cc -> 1 -> 99)
> (zz -> 0 -> ) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)
> 
> $ ./run.pl testdb
> === write testdb ===
> (aa -> 0 -> 1) (aa -> 1 -> 2) (aa -> 2 -> 3)
> (cc -> 0 -> 678) (cc -> 1 -> 99)
> (zz -> 0 -> foo) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)
> === read testdb ===
> (aa -> 0 -> 1) (aa -> 1 -> 2) (aa -> 2 -> 3)
> (cc -> 0 -> 678) (cc -> 1 -> 99)
> (zz -> 0 -> foo) (zz -> 1 -> fee) (zz -> 2 -> fuu) (zz -> 3 -> fun)
> 
> 
> 
> JL

This is from "man perltie":
> You cannot easily tie a multilevel data structure (such as a hash of 
> hashes) to a dbm file.  The first problem is that all but GDBM and 
> Berkeley DB have size limitations, but beyond that, you also have 
> problems with how references are to be represented on disk.


While arrays cannot be written directly to DB_File databases, you can 
easily create a db filter to convert an array reference to a string.

See this example:

#!/usr/bin/perl
use strict;
use warnings;
use DB_File;

my $db = '/tmp/file2.db';

write_dbf($db);
read_dbf($db);

sub write_dbf {
     my $filename = $_[0];
     tie my %h, 'DB_File', $filename, O_RDWR | O_CREAT, 0644
     or die "Tie failed: $!";
     sethandlers(\%h);

     while (<DATA>) {
         my ($k, @v) = split;
         $h{$k} = [@v];
     }

     untie %h;
}

sub read_dbf {
     my $filename = $_[0];
     tie my %h, 'DB_File', $filename, O_RDWR | O_CREAT, 0644
     or die "Tie failed: $!";
     sethandlers(\%h);

     while (my ($k, $v) = each %h) {
         print "$k => @{$v}\n";
     }

     untie %h;
}

sub sethandlers {
     my $obj = tied %{$_[0]};
     return unless defined $obj;
     $obj->filter_store_value(\&filter_store_value);
     $obj->filter_fetch_value(\&filter_fetch_value);
}

sub filter_store_value {
     $_ = join(',',@$_);
}

sub filter_fetch_value {
     $_ = [ split(',',$_)];
}

__DATA__
aa 1 2 3
cc 678 99
zz foo fee fuu fun

__END__

Try the program both with and without the calls to sethandlers.




------------------------------

Date: Tue, 22 Jun 2010 22:58:59 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 9.15 How do I parse a mail header?
Message-Id: <220620102258598400%brian.d.foy@gmail.com>

In article <hvne62$tdf$2@news.eternal-september.org>, Chris Nehren
<apeiron@isuckatdomains.net.invalid> wrote:

> On 2010-06-21, PerlFAQ Server scribbled these curious markings:
> > 9.15: How do I parse a mail header?
> 
> Another *CRINGE*. Email::Simple.

Patches welcome :)


------------------------------

Date: Tue, 22 Jun 2010 22:58:34 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 9.22 How do I read mail?
Message-Id: <220620102258346901%brian.d.foy@gmail.com>

In article <hvne5b$tdf$1@news.eternal-september.org>, Chris Nehren
<apeiron@isuckatdomains.net.invalid> wrote:

> On 2010-06-20, PerlFAQ Server scribbled these curious markings:
> > 9.22: How do I read mail?
> 
> *CRINGE*
> 
> *twitch*
> 
> At the very *least*, Email::Folder, please.

patches welcome. :)


------------------------------

Date: Tue, 22 Jun 2010 17:58:51 -0700
From: sln@netherlands.com
Subject: Re: How to use Regex to breakdown a pattern and use the pattern to break  down a string
Message-Id: <mvm226hdchh1e8j6f210dpiv2a6vfohtp7@4ax.com>

On Tue, 22 Jun 2010 15:14:45 -0700 (PDT), ChrisC <gjwpp88@gmail.com> wrote:

>I will get a user defined patten "XXXXX##', "##XXXXX##", "##XX##XX##",
>"XXX" etc.  How to break down this string pattern using Regex and
>apply it to data;
>
>Pattern "XXXXXXXX##" to break out string "00000078.7\r\n" to get
>"00000078.7";
>
>Pattern ""##XX##XX##" to break out string "LB78KL.7l\n" to get "78.7";
>
>etc......
>
>Or what is the best way to do this?
>
>Thanks,
>
>Jerry

I would think long and hard before doing this.

use strict;
use warnings;

my $data = "LB78KL.7l\n";
my $pat  = "##XX##XX##";

$pat =~ s/(X+)/'(' . '.'x length($1) . ')'/eg;
$pat =~ tr/#/./;
print join '', $data =~ /$pat/s;

-sln


------------------------------

Date: Tue, 22 Jun 2010 15:14:45 -0700 (PDT)
From: ChrisC <gjwpp88@gmail.com>
Subject: How to use Regex to breakdown a pattern and use the pattern to break  down a string
Message-Id: <9e3f4094-13f3-45c7-87a6-f8c0df376995@c15g2000vbl.googlegroups.com>

I will get a user defined patten "XXXXX##', "##XXXXX##", "##XX##XX##",
"XXX" etc.  How to break down this string pattern using Regex and
apply it to data;

Pattern "XXXXXXXX##" to break out string "00000078.7\r\n" to get
"00000078.7";

Pattern ""##XX##XX##" to break out string "LB78KL.7l\n" to get "78.7";

etc......

Or what is the best way to do this?

Thanks,

Jerry


------------------------------

Date: Tue, 22 Jun 2010 22:36:44 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: How to use Regex to breakdown a pattern and use the pattern to break  down a string
Message-Id: <slrni23014.b5j.tadmc@tadbox.sbcglobal.net>

ChrisC <gjwpp88@gmail.com> wrote:
> I will get a user defined patten "XXXXX##', "##XXXXX##", "##XX##XX##",
> "XXX" etc.  How to break down this string pattern using Regex and
> apply it to data;


That depends entirely on what meaning you assign to
the "X" and "#" characters in your pattern language.

What meaning do you assign to the "X" and "#" characters in your 
pattern language?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


------------------------------

Date: Tue, 22 Jun 2010 11:28:50 -0700 (PDT)
From: =?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?= <4ux6as402@sneakemail.com>
Subject: Proposing a new module: Parallel::Loops
Message-Id: <571e37f0-ddf5-4ae0-afeb-f6015aa82d69@r27g2000yqb.googlegroups.com>

perldoc perlmodlib suggests posting here before posting on CPAN, so
here goes:

I have a new module that I'd like to upload: Parallel::Loops, and
following is the bulk of the synopsis. Is the Parallel::Loops name
appropriate and does anybody have any comments on it before I post it
on CPAN?
Its repository can be found here (code, complete perldoc, etc.)
http://github.com/pmorch/perl-Parallel-Loops

Synopsis:

use Parallel::Loops;

my $maxProcs = 5;
my $pl = new Parallel::Loops($maxProcs);

my @input = ( 0 .. 9 );

my %output;
$pl->tieOutput( \%output );

$pl->foreach(
    \@input,
    sub {
        # This sub "magically" executed in parallel forked child
        # processes

        # Lets just create a simple example, but this could be a
        # massive calculation that will be parallelized, so that
        # $maxProcs different processes are calculating sqrt
        # simultaneously for different values of $_ on different CPUs

        $output{$_} = sqrt($_);
    }
);


------------------------------

Date: Wed, 23 Jun 2010 04:39:23 +0000
From: John Kelly <jak@isp2dial.com>
Subject: UNIX datagram sockets
Message-Id: <nc2326h8ho0v2kgifohqtpsft0c610f6oh@4ax.com>


Stein has an example of UNIX datagram sockets in his Networking book,
but it includes other ideas that, to me, made it hard to see the forest
for the trees.  So I distilled it down to the bare essential elements
related to socket setup.

I use a loop with 100,000 iterations to test performance, and get about
40,000 round trips per second.  A similar C solution gets about 55,000
round trips per second.  Because syscall and context switch overhead is
a limiting factor, the Perl code performs well compared to C.

Please ignore bad practices in this code, it's only intended to show how
to set up the datagram sockets, which to me, seemed mysterious without a
simple example.


--- CLIENT ---

#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket::UNIX;

my $peer = '/tmp/server.sock';
my $node = '/tmp/client1.sock';
unlink $node;

my $sock = IO::Socket::UNIX->new (
    Local => $node,
    Peer  => $peer,
    Type  => SOCK_DGRAM
) or die "$!";

my $tn;
my $data;

for ($tn = 1; $tn < 100000; $tn++) {

    send ($sock, '1234567890_blah_blah_blah', 0) or die "$!";
    recv ($sock, $data, 100, 0) or die "$!";

}

print "tn=$tn\n";



--- SERVER ---

#!/usr/bin/perl

use strict;
use warnings;
use IO::Socket::UNIX;

my $node = '/tmp/server.sock';
unlink $node;

my $sock = IO::Socket::UNIX->new (
    Local => $node,
    Type  => SOCK_DGRAM
) or die "$!";

my $peer;
my $data;

while (1) {

    $peer = recv ($sock, $data, 100, 0);
    send ($sock, $data, 0, $peer) || warn "$!";

}



-- 
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
 


------------------------------

Date: Wed, 23 Jun 2010 01:11:12 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: UNIX datagram sockets
Message-Id: <87y6e65o5r.fsf@quad.sysarch.com>

>>>>> "JK" == John Kelly <jak@isp2dial.com> writes:

  JK> Stein has an example of UNIX datagram sockets in his Networking book,
  JK> but it includes other ideas that, to me, made it hard to see the forest
  JK> for the trees.  So I distilled it down to the bare essential elements
  JK> related to socket setup.

  JK> I use a loop with 100,000 iterations to test performance, and get about
  JK> 40,000 round trips per second.  A similar C solution gets about 55,000
  JK> round trips per second.  Because syscall and context switch overhead is
  JK> a limiting factor, the Perl code performs well compared to C.

so what is your actual question?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 23 Jun 2010 05:24:51 +0000
From: John Kelly <jak@isp2dial.com>
Subject: Re: UNIX datagram sockets
Message-Id: <ah632698otqj7vlr8g7e07h55ves65ad3i@4ax.com>

On Wed, 23 Jun 2010 01:11:12 -0400, "Uri Guttman" <uri@StemSystems.com>
wrote:

>>>>>> "JK" == John Kelly <jak@isp2dial.com> writes:
>
>  JK> Stein has an example of UNIX datagram sockets in his Networking book,
>  JK> but it includes other ideas that, to me, made it hard to see the forest
>  JK> for the trees.  So I distilled it down to the bare essential elements
>  JK> related to socket setup.
>
>  JK> I use a loop with 100,000 iterations to test performance, and get about
>  JK> 40,000 round trips per second.  A similar C solution gets about 55,000
>  JK> round trips per second.  Because syscall and context switch overhead is
>  JK> a limiting factor, the Perl code performs well compared to C.
>
>so what is your actual question?

Do you expect all posts to ask for help?  Why?


-- 
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
 


------------------------------

Date: Wed, 23 Jun 2010 01:50:46 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: UNIX datagram sockets
Message-Id: <87tyou5mbt.fsf@quad.sysarch.com>

>>>>> "JK" == John Kelly <jak@isp2dial.com> writes:

  JK> On Wed, 23 Jun 2010 01:11:12 -0400, "Uri Guttman" <uri@StemSystems.com>
  JK> wrote:

  >>>>>>> "JK" == John Kelly <jak@isp2dial.com> writes:
  >> 
  JK> Stein has an example of UNIX datagram sockets in his Networking book,
  JK> but it includes other ideas that, to me, made it hard to see the forest
  JK> for the trees.  So I distilled it down to the bare essential elements
  JK> related to socket setup.
  >> 
  JK> I use a loop with 100,000 iterations to test performance, and get about
  JK> 40,000 round trips per second.  A similar C solution gets about 55,000
  JK> round trips per second.  Because syscall and context switch overhead is
  JK> a limiting factor, the Perl code performs well compared to C.
  >> 
  >> so what is your actual question?

  JK> Do you expect all posts to ask for help?  Why?

because they usually do. nothing you posted was signifigant as it was
basic udp code that you can get from modules, books, documentation,
etc. it wasn't particularly interesting even as a basic example. so if
you had a reason other than asking a question, you could have stated
that. seeing none, i had to ask why you posted it or you missed asking a
question.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Tue, 22 Jun 2010 19:50:53 -0700 (PDT)
From: Faith Greenwood <fgnowfg@gmail.com>
Subject: what cpu core is running the script?
Message-Id: <d3857a4a-ba96-45bc-8c15-e83cd17a4424@r14g2000vbc.googlegroups.com>

I have a windows machine (dual-core). Is there a way in perl to find
out what cpu core is running my script? I glanced through the Win32
modules but didn't see anything.


thanks


------------------------------

Date: Wed, 23 Jun 2010 09:05:41 +0200
From: Josef Moellers <josef.moellers@ts.fujitsu.com>
Subject: Re: what cpu core is running the script?
Message-Id: <hvsbn8$2u0$1@nntp.fujitsu-siemens.com>

Am 23.6.2010 schrub Faith Greenwood:

> I have a windows machine (dual-core). Is there a way in perl to find
> out what cpu core is running my script? I glanced through the Win32
> modules but didn't see anything.

It may have changed the moment you return from the call.


-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3000
***************************************


home help back first fref pref prev next nref lref last post