[28159] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9523 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 25 18:05:58 2006

Date: Tue, 25 Jul 2006 15:05:06 -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           Tue, 25 Jul 2006     Volume: 10 Number: 9523

Today's topics:
    Re: counting number of uniques in a multidimensional ar <mritty@gmail.com>
    Re: counting number of uniques in a multidimensional ar <jack_posemsky@yahoo.com>
    Re: counting number of uniques in a multidimensional ar <mritty@gmail.com>
    Re: counting number of uniques in a multidimensional ar <jack_posemsky@yahoo.com>
    Re: counting number of uniques in a multidimensional ar xhoster@gmail.com
    Re: counting number of uniques in a multidimensional ar <tzz@lifelogs.com>
    Re: counting number of uniques in a multidimensional ar <mritty@gmail.com>
    Re: counting number of uniques in a multidimensional ar <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: counting number of uniques in a multidimensional ar <jack_posemsky@yahoo.com>
    Re: counting number of uniques in a multidimensional ar axel@white-eagle.invalid.uk
        How to send utf-8 data using LWP::UserAgent? <g111@netcologne.de>
    Re: How to send utf-8 data using LWP::UserAgent? <hjp-usenet2@hjp.at>
    Re: perl + regex bug? nitroamos@gmail.com
    Re: Semantics of threads xhoster@gmail.com
    Re: Semantics of threads <blgl@stacken.kth.se>
        serial port blocking - windows sonnichs@berkshire.net
    Re: using session managment in perl <1usa@llenroc.ude.invalid>
    Re: using session managment in perl <noreply@gunnar.cc>
    Re: using session managment in perl <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Jul 2006 11:27:43 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <1153852063.407611.109500@i3g2000cwc.googlegroups.com>

Jack wrote:
> Hi I have data in a multidim array and DONT want to create another
> array representing just 1 column from this multidim array..

Why?

> I want to
> determine the number of uniques, I did this easily with just a regular
> array (code below), does anyone know how to do this over just 1 column
> of a multidim array (in other words, number of uniques across 1 column
> of the multi dim defined as: multidim[0][0],multidim[1][0],
> multidim[2][0].... etc)
>
> sort @$columnarray;

This does nothing at all.  You are clearly not enabling warnings in
your development.  Please start doing so.

> @out = grep($_ ne $prev && ($prev = $_, 1), @$columnarray);
> if ($#out == -1) { $#out = 0; }

"if @out is empty, create one undefined element in @out"

Why?  Under what circumstances do you believe @out could ever be empty
from the above code (assuming you had sorted @$columnarray correctly)?
Well, I suppose it could be if your array had nothing but undefined
values in it.  Is that the circumstance you were going for?

> $out = $#out +1; # makes $#out of 0 = 1 so it gets counted !

Now you're assigning $out to be the size of @out.  Why not just use the
size of @out?

> push @distinctcounts, $out;

The above code looks remarkably like the first answer to
perldoc -q duplicate

Have you seen the other answers?

Have you considered using map to generate a list of the first "columns"
of each array, and using that as your list rather than @{$columnarray}
?

map { $_->[0] } @$columnarray

will give you that.

Paul Lalli



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

Date: 25 Jul 2006 11:33:52 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <1153852432.163332.163800@m79g2000cwm.googlegroups.com>


Paul Lalli wrote:
> Jack wrote:
> > Hi I have data in a multidim array and DONT want to create another
> > array representing just 1 column from this multidim array..
>
> Why?
>
> > I want to
> > determine the number of uniques, I did this easily with just a regular
> > array (code below), does anyone know how to do this over just 1 column
> > of a multidim array (in other words, number of uniques across 1 column
> > of the multi dim defined as: multidim[0][0],multidim[1][0],
> > multidim[2][0].... etc)
> >
> > sort @$columnarray;
>
> This does nothing at all.  You are clearly not enabling warnings in
> your development.  Please start doing so.
>
> > @out = grep($_ ne $prev && ($prev = $_, 1), @$columnarray);
> > if ($#out == -1) { $#out = 0; }
>
> "if @out is empty, create one undefined element in @out"
>
> Why?  Under what circumstances do you believe @out could ever be empty
> from the above code (assuming you had sorted @$columnarray correctly)?
> Well, I suppose it could be if your array had nothing but undefined
> values in it.  Is that the circumstance you were going for?
>
> > $out = $#out +1; # makes $#out of 0 = 1 so it gets counted !
>
> Now you're assigning $out to be the size of @out.  Why not just use the
> size of @out?
>
> > push @distinctcounts, $out;
>
> The above code looks remarkably like the first answer to
> perldoc -q duplicate
>
> Have you seen the other answers?
>
> Have you considered using map to generate a list of the first "columns"
> of each array, and using that as your list rather than @{$columnarray}
> ?
>
> map { $_->[0] } @$columnarray
>
> will give you that.
>
> Paul Lalli

Just ignore the @$ (this represents a variable) - assume the code is
this:
sort @columnarray;
@out = grep($_ ne $prev && ($prev = $_, 1), @columnarray);
if ($#out == -1) { $#out = 0; }
print $out;

Are you saying the above doesnt work ?? It works great on a single
array.  Do you have a better code, if so, what is it ?  Also, can you
please answer the question about how to get the distinct count of a
multidim column with an actual example.  Appreciate your response.
Thanks, Jack



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

Date: 25 Jul 2006 11:40:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <1153852804.585915.309840@i42g2000cwa.googlegroups.com>

Jack wrote:

> Just ignore the @$ (this represents a variable)

There was no @$ in your original snippet, so ignoring it is a no-op.
There was, however, @$columnarray, which is a perfectly valid array.  I
have no idea why you're saying to get rid of it now.

> - assume the code is this:
> sort @columnarray;

Once again, THIS LINE DOES NOTHING.  You still have not bothered to
turn warnings on?  Why?  You are asking for help, help is being given
to you, and you're ignoring it.  That's really very annoying.

> @out = grep($_ ne $prev && ($prev = $_, 1), @columnarray);
> if ($#out == -1) { $#out = 0; }
> print $out;
>
> Are you saying the above doesnt work ??

I did not say that at all. What part of my post implies that the code
doesn't work?  I said that the first line of it does nothing at all,
and the messing about with $#out is pointless.

> It works great on a single
> array.  Do you have a better code, if so, what is it ?

Once again, I point you to the other responses in the FAQ that you
apparently saw to get this code:
perldoc -q duplicate
(Or did you never see that FAQ, and are instead just copy/pasting some
other code you found lying around somewhere?)
Once again, why are you ignoring what I've already told you to do,
preferring instead to believe that I'm just not bothering to help?

>  Also, can you
> please answer the question about how to get the distinct count of a
> multidim column with an actual example

I *did*!  Why are you ignoring my entire response?!  I told you
precisely how to change your example to use a list of the first
columns, rather than a single array.  The fact that you ignored that
advice is your problem, not mine.

>  Appreciate your response.

Really doesn't appear that way.

Paul Lalli



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

Date: 25 Jul 2006 11:54:38 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <1153853677.967693.276170@i3g2000cwc.googlegroups.com>


Paul Lalli wrote:
> Jack wrote:
>
> > Just ignore the @$ (this represents a variable)
>
> There was no @$ in your original snippet, so ignoring it is a no-op.
> There was, however, @$columnarray, which is a perfectly valid array.  I
> have no idea why you're saying to get rid of it now.
>
> > - assume the code is this:
> > sort @columnarray;
>
> Once again, THIS LINE DOES NOTHING.  You still have not bothered to
> turn warnings on?  Why?  You are asking for help, help is being given
> to you, and you're ignoring it.  That's really very annoying.
>
> > @out = grep($_ ne $prev && ($prev = $_, 1), @columnarray);
> > if ($#out == -1) { $#out = 0; }
> > print $out;
> >
> > Are you saying the above doesnt work ??
>
> I did not say that at all. What part of my post implies that the code
> doesn't work?  I said that the first line of it does nothing at all,
> and the messing about with $#out is pointless.
>
> > It works great on a single
> > array.  Do you have a better code, if so, what is it ?
>
> Once again, I point you to the other responses in the FAQ that you
> apparently saw to get this code:
> perldoc -q duplicate
> (Or did you never see that FAQ, and are instead just copy/pasting some
> other code you found lying around somewhere?)
> Once again, why are you ignoring what I've already told you to do,
> preferring instead to believe that I'm just not bothering to help?
>
> >  Also, can you
> > please answer the question about how to get the distinct count of a
> > multidim column with an actual example
>
> I *did*!  Why are you ignoring my entire response?!  I told you
> precisely how to change your example to use a list of the first
> columns, rather than a single array.  The fact that you ignored that
> advice is your problem, not mine.
>
> >  Appreciate your response.
>
> Really doesn't appear that way.
>
> Paul Lalli

Forgive me if I am limited to some degree.  I am just asking if someone
can provide some sample code that works takes $multidimarray[1][0],
$multidimarray[2][0], (a column) and produces a distinct count...

I dont know how to take your suggestion of
map { $_->[0] } @columnarray
and convert that into a solution for that counts the distinct entires
for the first column in a multidimensional array ..

Would you consider elaborating, or perhaps someone who is willing to
help/share.

Thank you,
Jack



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

Date: 25 Jul 2006 19:07:30 GMT
From: xhoster@gmail.com
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <20060725151358.703$O7@newsreader.com>

"Jack" <jack_posemsky@yahoo.com> wrote:
> Hi I have data in a multidim array and DONT want to create another
> array representing just 1 column from this multidim array.. I want to
> determine the number of uniques, I did this easily with just a regular
> array (code below),

I don't know if the code below actually does work, but I will assume it
does.

> does anyone know how to do this over just 1 column
> of a multidim array (in other words, number of uniques across 1 column
> of the multi dim defined as: multidim[0][0],multidim[1][0],
> multidim[2][0].... etc)

my $col_number=0; # or whatever column you want
my $columnarray=[map $_->[$col_number], @multidim];

Now procede as before with $columnarray.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 25 Jul 2006 15:20:11 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <g693bcpmqz8.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 25 Jul 2006, jack_posemsky@yahoo.com wrote:

> Forgive me if I am limited to some degree.  I am just asking if someone
> can provide some sample code that works takes $multidimarray[1][0],
> $multidimarray[2][0], (a column) and produces a distinct count...
>
> I dont know how to take your suggestion of
> map { $_->[0] } @columnarray
> and convert that into a solution for that counts the distinct entires
> for the first column in a multidimensional array ..

I'll try to help you.  Keep in mind that the advice Paul gave was
useful, I'm just restating it and elaborating.  Don't feel bad about
missing things here and there, everyone has to start somewhere.

That map call will return the first (0) column of the array as a list.

Your original question was how to find unique elements in a column.

You posted:

> sort @$columnarray;
> @out = grep($_ ne $prev && ($prev = $_, 1), @$columnarray);
> if ($#out == -1) { $#out = 0; }
> $out = $#out +1; # makes $#out of 0 = 1 so it gets counted !
> push @distinctcounts, $out;

The first line does nothing at all.  Paul mentioned that too.  Use
warnings and strict mode, if possible, to avoid such code.  Sort
*returns* the sorted list, it doesn't modify in place.

In addition your 'uniques' code is not very good.  It may work in some
cases, but really you should use a hash.  Look at 'perldoc -q
duplicates' and 'perldoc perldata' to get started.  Actually all of
the perldoc info is good :)

Here's a (very simple) function to give you the unique items from a
list you pass:

sub uniques
{
 my %unique = ();
 $unique{$_}++ foreach @_;
 return keys %unique;
}

Now use it like this:

my @columnarray = ( [1,2,3], [1,2,3], [4,5,6], [7,8,9], );

foreach my $column (1 .. scalar @{$columnarray[0]})
{
 print "Unique elements in column $column: ";
 print join ', ', 
       uniques(map { $_->[$column-1] } 
                   @columnarray
              );
 print "\n";
}

I formatted this to be easy to understand, and I tested it with the
data above under

use warnings;
use strict;

and it worked correctly.  Please learn from the code posted above - it
shows many useful techniques.

Ted


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

Date: 25 Jul 2006 13:02:43 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <1153857763.452460.31230@b28g2000cwb.googlegroups.com>

Jack wrote:
> Paul Lalli wrote:
> > > @out = grep($_ ne $prev && ($prev = $_, 1), @columnarray);

> > >  Also, can you
> > > please answer the question about how to get the distinct count of a
> > > multidim column with an actual example
> >
> > I *did*!  Why are you ignoring my entire response?!  I told you
> > precisely how to change your example to use a list of the first
> > columns, rather than a single array.  The fact that you ignored that
> > advice is your problem, not mine.
> >

> Forgive me if I am limited to some degree.

Being new to Perl is not something that requires forgiveness.  Being
unwilling to put forth effort of your own, and only accepting solutions
that are spoonfed to you, is not worthy of forgiveness.

>  I am just asking if someone can provide some sample code

I know exactly what you're asking.  I have answered it 3 times now.
The answer is "No, I will not write code for you.   I will, however,
give you all the information you need to do it yourself."  If that's
not good enough for you, I strongly suggest you hire a consultant.

> that works takes $multidimarray[1][0],
> $multidimarray[2][0], (a column) and produces a distinct count...
>
> I dont know how to take your suggestion of
> map { $_->[0] } @columnarray
> and convert that into a solution for that counts the distinct entires
> for the first column in a multidimensional array ..

I told you to take that expression, and operate on that, rather than on
@columnarray itself.  What part of that is confusing to you?

Take that expression right there, and put that where you currently have
'@columnarray' in the first quoted line of this message.

> Would you consider elaborating, or perhaps someone who is willing to
> help/share.

Implying that I am *not* willing to help or share?  You have a very
bizarre definition of "help".

*PLONK*

Paul Lalli



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

Date: Tue, 25 Jul 2006 20:10:36 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <0Vuxg.9871$vO.5724@newsread4.news.pas.earthlink.net>

On 07/25/2006 01:54 PM, Jack wrote:
> Paul Lalli wrote:
>> [ snipped ]
> [...]
> I dont know how to take your suggestion of
> map { $_->[0] } @columnarray
> and convert that into a solution for that counts the distinct entires
> for the first column in a multidimensional array ..
> 
> Would you consider elaborating, or perhaps someone who is willing to
> help/share.
> 
> Thank you,
> Jack
> 

Paul Lalli gave you half of the answer. You're supposed to
figure out the other half. The other half is storing the data
in a hash where the keys are the column data returned from the
map, and the values are incremented once for each entry in the
column.

Hashes have a "magical" quality that makes their keys unique.
Using a hash, you can count the number of unique items in an
array, because each key in a hash appears only once.

1: use Data::Dumper;
2: my @temps = (30, 38, 26, 38, 39);
3: my %hash;
4: for my $tp (@temps) { $hash{$tp} += 1 }
5: print Dumper(\%hash);

Line 4 increments a hash value each time it's found[0] in the
array. Notice that 38 only appears once in the hash, despite
the fact that it appears twice in @temps.


:-O UNTESTED CODE :-O

-- 
[0] Simplified language. Untrue.


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

Date: 25 Jul 2006 13:54:11 -0700
From: "Jack" <jack_posemsky@yahoo.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <1153860851.921617.275800@h48g2000cwc.googlegroups.com>


Ted Zlatanov wrote:
> On 25 Jul 2006, jack_posemsky@yahoo.com wrote:
>
> > Forgive me if I am limited to some degree.  I am just asking if someone
> > can provide some sample code that works takes $multidimarray[1][0],
> > $multidimarray[2][0], (a column) and produces a distinct count...
> >
> > I dont know how to take your suggestion of
> > map { $_->[0] } @columnarray
> > and convert that into a solution for that counts the distinct entires
> > for the first column in a multidimensional array ..
>
> I'll try to help you.  Keep in mind that the advice Paul gave was
> useful, I'm just restating it and elaborating.  Don't feel bad about
> missing things here and there, everyone has to start somewhere.
>
> That map call will return the first (0) column of the array as a list.
>
> Your original question was how to find unique elements in a column.
>
> You posted:
>
> > sort @$columnarray;
> > @out = grep($_ ne $prev && ($prev = $_, 1), @$columnarray);
> > if ($#out == -1) { $#out = 0; }
> > $out = $#out +1; # makes $#out of 0 = 1 so it gets counted !
> > push @distinctcounts, $out;
>
> The first line does nothing at all.  Paul mentioned that too.  Use
> warnings and strict mode, if possible, to avoid such code.  Sort
> *returns* the sorted list, it doesn't modify in place.
>
> In addition your 'uniques' code is not very good.  It may work in some
> cases, but really you should use a hash.  Look at 'perldoc -q
> duplicates' and 'perldoc perldata' to get started.  Actually all of
> the perldoc info is good :)
>
> Here's a (very simple) function to give you the unique items from a
> list you pass:
>
> sub uniques
> {
>  my %unique = ();
>  $unique{$_}++ foreach @_;
>  return keys %unique;
> }
>
> Now use it like this:
>
> my @columnarray = ( [1,2,3], [1,2,3], [4,5,6], [7,8,9], );
>
> foreach my $column (1 .. scalar @{$columnarray[0]})
> {
>  print "Unique elements in column $column: ";
>  print join ', ',
>        uniques(map { $_->[$column-1] }
>                    @columnarray
>               );
>  print "\n";
> }
>
> I formatted this to be easy to understand, and I tested it with the
> data above under
>
> use warnings;
> use strict;
>
> and it worked correctly.  Please learn from the code posted above - it
> shows many useful techniques.
>
> Ted

Ted, great job that works killer... can you tell me, I want to exclude
from the counting any null values, I tried adding this without
success..any reply would be appreciated..thanks, Jack

sub uniques
{
 my %unique = ();
 if (@_ != /^\z/) { $unique{$_}++ foreach @_ }  ;
 return keys %unique; 
}



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

Date: Tue, 25 Jul 2006 22:03:38 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <_ywxg.7220$5K2.4272@fed1read03>

Jack <jack_posemsky@yahoo.com> wrote:
 
> sort @columnarray;
> @out = grep($_ ne $prev && ($prev = $_, 1), @columnarray);
> if ($#out == -1) { $#out = 0; }
> print $out;
 
> Are you saying the above doesnt work ?? It works great on a single
> array.  Do you have a better code, if so, what is it ?  

It doesn't work. Even if the last line if a typo for

	print $#out;

    my @columnarray = qw(a b c d  b e c);                                                                                                            
Results in:

    Useless use of sort in void context at q1.pl line 11.
    Use of uninitialized value in string ne at q1.pl line 12.
    6

> Also, can you
> please answer the question about how to get the distinct count of a
> multidim column with an actual example.  Appreciate your response.

People on this group do not regard to being told to answer questions or
write code.

Axel



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

Date: Tue, 25 Jul 2006 20:19:03 +0200
From: Gert Brinkmann <g111@netcologne.de>
Subject: How to send utf-8 data using LWP::UserAgent?
Message-Id: <ea5nam$2t6$1@newsreader2.netcologne.de>

Hello,

I am using LWP::UserAgent to send utf-8 encoded xml-data to a web-server.

        my $req = HTTP::Request->new (
                POST => "http://myhost:8181",
                HTTP::Headers->new (
                        'content-type' => "text/xml; charset=utf-8",
                ),
                $xml_data,
        );

        my $ua   = LWP::UserAgent->new;
        my $resp = $ua->simple_request($req);

The problem ist, that lwp seems to convert the utf-8 data to iso-latin. I
have checked this by listening on the port 8181 via: "netcat -l -p 8181".
German Umlauts do occur there correctly readable as äöüß, but IMHO should
not.

I also have checked that the terminal is not converting the data by writing
a file using gedit that contains the string "gört" and netcat'ing it to the
port 8181. The result is: "gört" as expected.

What am I doing wrong?

Thanks,
Gert



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

Date: Tue, 25 Jul 2006 22:01:16 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to send utf-8 data using LWP::UserAgent?
Message-Id: <pan.2006.07.25.20.01.16.60739@hjp.at>

On Tue, 25 Jul 2006 20:19:03 +0200, Gert Brinkmann wrote:
> I am using LWP::UserAgent to send utf-8 encoded xml-data to a web-server.
> 
>         my $req = HTTP::Request->new (
>                 POST => "http://myhost:8181",
>                 HTTP::Headers->new (
>                         'content-type' => "text/xml; charset=utf-8",
>                 ),
>                 $xml_data,
>         );
> 
>         my $ua   = LWP::UserAgent->new;
>         my $resp = $ua->simple_request($req);
> 
> The problem ist, that lwp seems to convert the utf-8 data to iso-latin. I
> have checked this by listening on the port 8181 via: "netcat -l -p 8181".
> German Umlauts do occur there correctly readable as äöüß, but IMHO should
> not.
[...]
> What am I doing wrong?

You are not providing a complete script to demonstrate your problem.
Where does $xml_data come from? How do you know that it contains UTF-8?

Dump $xml_data in hex to see what it really contains:

printf STDERR "%x ", ord($_) for (split//, $xml_data);

If "gört" is printed as 
67 f6 72 74 
it's not UTF-8. It should be
67 c3 b6 72 74

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd



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

Date: 25 Jul 2006 11:37:33 -0700
From: nitroamos@gmail.com
Subject: Re: perl + regex bug?
Message-Id: <1153852653.614459.230060@s13g2000cwa.googlegroups.com>

I tried your recommended fixes on the machine where I was having the
problem, and they don't seem to be making a difference. Based on the
suspicion that something is system dependent, I just tried the original
script on an OSX machine, where:

"This is perl, v5.8.6 built for darwin-thread-multi-2level"

And it seems that my original script works. That is, whatever it was
that I was seeing was a bug in perl, but that it was fixed at some
point. Thus, it now seems to me a waste of time to attempt further
diagnosis.

My conclusion is that (ignoring TIMTOWTDI) sometimes even perl can have
strange bugs -- especially older versions. fortunately, perl is diverse
enough that there are always ways around the problem.



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

Date: 25 Jul 2006 18:57:07 GMT
From: xhoster@gmail.com
Subject: Re: Semantics of threads
Message-Id: <20060725150335.583$GO@newsreader.com>

Bo Lindbergh <blgl@stacken.kth.se> wrote:
> In article <20060724143437.507$9O@newsreader.com>, xhoster@gmail.com
> wrote:
> > Bo Lindbergh <blgl@stacken.kth.se> wrote:
> > > perldoc perlthrtut says:
> > > > Thinking of mixing fork() and threads?  Please lie down and wait
> > > > until the feeling passes.  Be aware that the semantics of fork()
> > > > vary between platforms.  For example, some UNIX systems copy all
> > > > the current threads into the child process, while others only copy
> > > > the thread that called fork(). You have been warned!
> > >
> > > Does this mean that if more than one thread exists, the qx operator,
> > > the system function, and the open function in pipe mode all have
> > > undefined behaviour?
> >
> > Excluding bugs, no, the behaviour is not undefined.  Those operations
> > are not implemented merely as naive forks.  They are implemented in
> > different ways on different machines, and (attempt to) take care of
> > such issues.
>
> Really?  I looked at the source and found no attempts to block other
> threads from running between the fork and the exec.

It would really help to know what version of the source you looked at, and
the file(s) and line numbers.  Anyway, I think there are some destruction
flags that need to be cleared/bypassed on a fork done within a thread to
avoid problems, which are inherently bypassed by doing an exec so in that
case perhaps no other special code is needed.  The key (under unix) seems
to be to explicitly exit the forked child, and not let it run off the end
of the thread. But I wouldn't gaurantee that to always work (and I
generally just avoid threads anyway on unix, so my experience is limited).


perl-5.8.8]$ perl -le 'use threads; async{warn "In thread"; sleep 2; if
(fork) { print "a"} else {}}->join(); print "b"; sleep 5'

In thread at -e line 1.
Unbalanced scopes: 3 more ENTERs than LEAVEs
Unbalanced saves: 8 more saves than restores
Unbalanced context: 2 more PUSHes than POPs
Segmentation fault (core dumped)

Adding an exit to the empty "else {}" solves this problem.  However,
removing the "sleep 2;" also solves the problem, for reasons I don't
understand.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 25 Jul 2006 23:03:54 +0200
From: Bo Lindbergh <blgl@stacken.kth.se>
Subject: Re: Semantics of threads
Message-Id: <ea60vq$8h7$1@news.su.se>

In article <20060725150335.583$GO@newsreader.com>, xhoster@gmail.com 
wrote:

> Bo Lindbergh <blgl@stacken.kth.se> wrote:
> > Really?  I looked at the source and found no attempts to block other
> > threads from running between the fork and the exec.
> 
> It would really help to know what version of the source you looked at, and
> the file(s) and line numbers

5.9.3, pp_sys.c, line 3950: start of pp_system.
line 3956: taint handling.
line 3966: output buffer flushing.
line 3975: fork attempts start here.
No sign of any thread-related stuff.


/Bo Lindbergh


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

Date: 25 Jul 2006 12:56:14 -0700
From: sonnichs@berkshire.net
Subject: serial port blocking - windows
Message-Id: <1153857374.483217.314150@b28g2000cwb.googlegroups.com>

Can anyone tell me how to control whether windows operates in
blocking/nonblocking mode when programming the serial port with perl?
It does not appear that I can use a system call to the windows "mode"
command for this.

Thanks.
Fritz



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

Date: Tue, 25 Jul 2006 18:57:35 +0000 (UTC)
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: using session managment in perl
Message-Id: <Xns980B982D98750asu1cornelledu@132.236.56.8>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:4in3alF4clkvU1
@individual.net:

> A. Sinan Unur wrote:
>> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
>> news:4imuqmF4gnj6U1@individual.net: 
>>>A. Sinan Unur wrote:
>>>>
>>>>* CGI questions are off-topic in this newsgroup.
>>>
>>>Only if they have no Perl content.
>> 
>> There was no Perl content in the OP:
>> 
>> http://groups.google.com/group/comp.lang.perl.misc/msg/c81bcc45d6684b5b
> 
> True, but that does not make the above unqualified statement correct.
> 

No, but the rest of the message explained what to do to make the post 
topical. I did not see the point of your correction, especially given that 
I stated, in the same post:

      On the other hand, if you have some Perl code that is, say, using 
      CGI::Session, and is not behaving as you expect, then by all means, 
      ask a specific question, *AFTER* reading the posting guidelines for 
      this group.


I still do not see the point of your correction. Not every fact needs to be 
mentioned in the same sentence, and, overall, my response did convey the 
fact that Perl questions might have something to do with CGI are not ruled 
out, just CGI questions that have no Perl content.

I am going to stop now.

Sinan


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

Date: Tue, 25 Jul 2006 23:10:30 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: using session managment in perl
Message-Id: <4info7F4jedoU1@individual.net>

A. Sinan Unur wrote:
> Gunnar Hjalmarsson wrote:
>>A. Sinan Unur wrote:
>>>Gunnar Hjalmarsson wrote: 
>>>>A. Sinan Unur wrote:
>>>>>* CGI questions are off-topic in this newsgroup.
>>>>
>>>>Only if they have no Perl content.
>>>
>>>There was no Perl content in the OP:
>>>
>>>http://groups.google.com/group/comp.lang.perl.misc/msg/c81bcc45d6684b5b
>>
>>True, but that does not make the above unqualified statement correct.
> 
> No, but the rest of the message explained what to do to make the post 
> topical. I did not see the point of your correction,

Maybe I'm oversensitive...

> my response did convey the 
> fact that Perl questions might have something to do with CGI are not ruled 
> out, just CGI questions that have no Perl content.

Unfortunately, that's not an undisputed fact. I often see remarks here, 
apparently with the aim to discourage people from posting anything CGI 
related. That's the reason for my oversensitiveness.

OTOH, you often post helpful replies to CGI related Perl questions, so 
it was kind of unfair to 'pick' on you. Sorry about that. ;-)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Tue, 25 Jul 2006 21:49:32 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: using session managment in perl
Message-Id: <Xns980BB56DCD1DEasu1cornelledu@127.0.0.1>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
news:4info7F4jedoU1@individual.net: 

> A. Sinan Unur wrote:

[ back and forth argument snipped  ;-) ]

>> my response did convey the 
>> fact that Perl questions might have something to do with CGI are not
>> ruled out, just CGI questions that have no Perl content.
> 
> Unfortunately, that's not an undisputed fact. I often see remarks
> here, apparently with the aim to discourage people from posting
> anything CGI related. That's the reason for my oversensitiveness.

Understood. I think we both agree that it is unfortunate when legitimate 
Perl questions that are related to CGI are considered off-topic. 

> OTOH, you often post helpful replies to CGI related Perl questions, so
> it was kind of unfair to 'pick' on you. Sorry about that. ;-)

No need to apologize. We both stated our positions, and re-reading my 
posts, I think I might be the oversensitive one ;-)

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.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:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#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 V10 Issue 9523
***************************************


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