[30720] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1965 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 5 14:09:45 2008

Date: Wed, 5 Nov 2008 11:09:10 -0800 (PST)
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, 5 Nov 2008     Volume: 11 Number: 1965

Today's topics:
    Re: creating an array of $n elements <samwyse@gmail.com>
        FFT on a wav file <kieranocall@gmail.com>
    Re: hash array loop in sequence? <xemoth@gmail.com>
    Re: hash array loop in sequence? <smallpond@juno.com>
    Re: hash array loop in sequence? <jurgenex@hotmail.com>
    Re: hash array loop in sequence? xhoster@gmail.com
        Help: How can I parse this properties file? <yuanyun.ken@gmail.com>
    Re: Help: How can I parse this properties file? <jurgenex@hotmail.com>
    Re: Help: How can I parse this properties file? <tadmc@seesig.invalid>
    Re: Help: How can I parse this properties file? <tzz@lifelogs.com>
    Re: ImageMagick: Writing image with 4 colors and palett <zentara@highstream.net>
        perl maximum memory <michaelgang@gmail.com>
    Re: perl maximum memory <hjp-usenet2@hjp.at>
    Re: Perl Presentation <cwilbur@chromatico.net>
    Re: Perl Presentation <tzz@lifelogs.com>
        Problem In Setting Up ptkdb for mod_perl <yancheng.cheok@gmail.com>
        Sockets and threads... <Mark.Seger@hp.com>
    Re: Sockets and threads... <zentara@highstream.net>
    Re: Sockets and threads... xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 5 Nov 2008 05:32:41 -0800 (PST)
From: samwyse <samwyse@gmail.com>
Subject: Re: creating an array of $n elements
Message-Id: <bfcd0525-9bec-43c9-99c7-074d50f9ecdc@l33g2000pri.googlegroups.com>

On Nov 4, 9:31=A0pm, samwyse <samw...@gmail.com> wrote:
> In Python, I can say "7 * (1,)" to create a list of 7 items. If I need
> a list in Perl with all elements initialized to the same value, is
> there a one-liner? =A0The best I can come up with is "$a[$n] =3D 0; pop
> @a;" which will give me an array of $n undefs, but it seems a bit
> inefficient. =A0Any ideas? =A0Thanks.

Thanks to everyone.  For some reason, I was thinking that the 'x'
operator only applied to strings.  D'oh!


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

Date: Wed, 5 Nov 2008 09:24:19 -0800 (PST)
From: kieran <kieranocall@gmail.com>
Subject: FFT on a wav file
Message-Id: <21ae61da-6c64-4fb8-8713-d9061caa6144@u29g2000pro.googlegroups.com>

Hi all,
after trying a few different modules to perform an FFT on a WAV file I
settled on the following one, Freqext.
http://tomacorp.com/perl/wav/Freqext.html
I used some of the sample code on the above page to track a moving
frequency "Using the FFT to Track a Moving Frequency".
The outputI am getting back looks correct but for a 13 second file all
the results are compressed into the first half of the output. The
application is returning a long list of results split up over the 13
seconds,  see example output below. All the results unp until 1/2 the
length of the wav file are fine but the second half is always empty.
If the first half of the results were spread over the entire length of
the file it would be correct.
I have tried many different wav files of different length and sample
rate, also i have tried every different size of fft between 8 and
262144.
Any Ideas?
Hope you can help,
Kieran
 ....
4.5  5.678
5.0  1.234
5.5  4.567
6.0  3.456
6.5  0.000
7.0  0.000
7.5  0.000
8.0  0.000
 .....


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

Date: Wed, 5 Nov 2008 03:09:16 -0800 (PST)
From: Owen <xemoth@gmail.com>
Subject: Re: hash array loop in sequence?
Message-Id: <fa86583a-91c5-42ee-91f8-4f519f456478@r36g2000prf.googlegroups.com>

On Nov 5, 6:55=A0pm, Slickuser <slick.us...@gmail.com> wrote:
> my %data =3D (
> =A0 =A0 =A0 =A0 "name" =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D> "BOB",
> =A0 =A0 =A0 =A0 "age" =A0 =A0 =A0 =A0 =3D> 35,
> =A0 =A0 =A0 =A0 "sex" =A0 =A0 =A0 =A0 =3D> "M",
> =A0 =A0 =A0 =A0 "phone" =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D> "555-5555",
> =A0 =A0 =A0 =A0 "city" =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=3D> "LA",
> =A0 =A0 =A0 =A0 "state" =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D> "CA",
> =A0 =A0 =A0 =A0 "country" =A0 =A0 =3D> "US"
> );
>
> foreach my $entry (keys %data)
> {
> =A0 =A0 =A0 =A0 print $entry ." ". $data{$entry} ."\n";
> =A0 =A0 =A0 =A0 ##can't use sort keys or values
>
> }
>
> If I got my hash array like this.
> How can loop through in the order of name, age, sex, phone, city,
> state, country?

You might want to try and array of your keys in the order you want

my @array =3D("name","age", etc);

then for each entry, loop through the array values printing
$data{$array[n]}



Owen


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

Date: Wed, 5 Nov 2008 06:47:14 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: hash array loop in sequence?
Message-Id: <9e28d588-fa8d-46fa-ac91-994d8dae1f46@x1g2000prh.googlegroups.com>

On Nov 5, 2:55 am, Slickuser <slick.us...@gmail.com> wrote:
> my %data = (
>         "name"                => "BOB",
>         "age"         => 35,
>         "sex"         => "M",
>         "phone"               => "555-5555",
>         "city"                => "LA",
>         "state"               => "CA",
>         "country"     => "US"
> );
>
> foreach my $entry (keys %data)
> {
>         print $entry ." ". $data{$entry} ."\n";
>         ##can't use sort keys or values
>
> }
>
> If I got my hash array like this.
> How can loop through in the order of name, age, sex, phone, city,
> state, country?


foreach my $entry qw(name age sex phone city state country )
{
  print $entry ." ". $data{$entry} ."\n";
}


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

Date: Wed, 05 Nov 2008 07:14:53 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: hash array loop in sequence?
Message-Id: <9ed3h49pnaaq1fifuahlfol886gf0pui76@4ax.com>

Slickuser <slick.users@gmail.com> wrote:
>my %data = (
>	"name"		=> "BOB",
>	"age"		=> 35,
>	"sex"		=> "M",
>	"phone"		=> "555-5555",
>	"city"		=> "LA",
>	"state"		=> "CA",
>	"country"	=> "US"
>);
>

>If I got my hash array like this.
>How can loop through in the order of name, age, sex, phone, city,
>state, country?

Sorted by any of those values or sorted by all of those values, i.e.
people with same name will be sorted further by age, and those with same
name and age will be sorted further by sex?

Either way, see the man page as well as 'perldoc -q sort'.

If the former then e.g. (sketch only, untested):

@sorted = sort {$a{name} cmp $b{name}} , keys(%data);
foreach (@sorted){
	print $_;
}

If the latter then you got two options:
- Perl's sort() is stable. Therefore you can sort by the lowest criteria
first. And then sort again by the second-lowest and the third-lowest
etc. until the last pass is with your top criteria. This is expensive
because you are sorting the same data many times over.
- or you can do it in one pass by simply creating a proper custom
compare function as described in the man page and the FAQ.

jue


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

Date: 05 Nov 2008 17:41:27 GMT
From: xhoster@gmail.com
Subject: Re: hash array loop in sequence?
Message-Id: <20081105124159.951$qb@newsreader.com>

smallpond <smallpond@juno.com> wrote:

> foreach my $entry qw(name age sex phone city state country )
> {
>   print $entry ." ". $data{$entry} ."\n";
> }

I was surprised that this works.  I thought the list of a foreach *had* to
be in parentheses, and that the qw() wouldn't count as parentheses.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Wed, 5 Nov 2008 05:23:58 -0800 (PST)
From: "yuanyun.ken" <yuanyun.ken@gmail.com>
Subject: Help: How can I parse this properties file?
Message-Id: <c0023e18-0290-4999-87f3-8afea3fd4d97@o4g2000pra.googlegroups.com>

Hi, dear all perl users:
Recently I need read in a proerties file,
its format is key=value, and it uses \ to escape.
for example:
expression  means:    key     value
a=b=c                           a        b=c
a\=b=c                          a=b      c
a\\=b=c                         a\       b=c
a\\\=b=c                        a\=b     c

How can I parse this file?
I think it should use regex.
but my knowledage in Regular expression is poor.
any help is greatly appreciated.


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

Date: Wed, 05 Nov 2008 07:22:26 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Help: How can I parse this properties file?
Message-Id: <96e3h45q705a5ahndei3fr2f43i5kpsl7l@4ax.com>

"yuanyun.ken" <yuanyun.ken@gmail.com> wrote:
>Recently I need read in a proerties file,
>its format is key=value, and it uses \ to escape.
>for example:
>expression  means:    key     value
>a=b=c                           a        b=c
>a\=b=c                          a=b      c
>a\\=b=c                         a\       b=c
>a\\\=b=c                        a\=b     c
>
>How can I parse this file?
>I think it should use regex.
>but my knowledage in Regular expression is poor.

No need for complex REs. Just have the tokenizer walk through the file
character by character and when it finds a backslash then immeditately
read another character and return that literal character as the next
character in the token, no matter if it is a normal character, another
backslash, or an equal sign.

jue


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

Date: Wed, 5 Nov 2008 11:03:42 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Help: How can I parse this properties file?
Message-Id: <slrngh3kfe.sem.tadmc@tadmc30.sbcglobal.net>

yuanyun.ken <yuanyun.ken@gmail.com> wrote:
> Hi, dear all perl users:
> Recently I need read in a proerties file,
> its format is key=value, and it uses \ to escape.
> for example:
> expression  means:    key     value
> a=b=c                           a        b=c
> a\=b=c                          a=b      c
> a\\=b=c                         a\       b=c
> a\\\=b=c                        a\=b     c
>
> How can I parse this file?


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

foreach my $line ( <DATA> ) {
    chomp $line;
    $line =~ s/\\\\/&backslash;/g;  # translate literal backslashes

    my($key, $value) = split /(?<!\\)=/, $line, 2; # use negative look-behind

    $key =~ tr/\\//d;  # eliminate backslashes used for escaping

    $key =~ s/&backslash;/\\/g; # put the literal backslashes back in

    printf "%-10s   %-10s\n", $key, $value;
}

__DATA__
a=b=c
a\=b=c
a\\=b=c
a\\\=b=c
----------------------------


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Wed, 05 Nov 2008 11:28:24 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Help: How can I parse this properties file?
Message-Id: <86k5biozev.fsf@lifelogs.com>

On Wed, 5 Nov 2008 11:03:42 -0600 Tad J McClellan <tadmc@seesig.invalid> wrote: 

TJM> #!/usr/bin/perl
TJM> use warnings;
TJM> use strict;

TJM> foreach my $line ( <DATA> ) {
TJM>     chomp $line;
TJM>     $line =~ s/\\\\/&backslash;/g;  # translate literal backslashes

TJM>     my($key, $value) = split /(?<!\\)=/, $line, 2; # use negative look-behind

TJM>     $key =~ tr/\\//d;  # eliminate backslashes used for escaping

TJM>     $key =~ s/&backslash;/\\/g; # put the literal backslashes back in

TJM>     printf "%-10s   %-10s\n", $key, $value;
TJM> }

TJM> __DATA__
TJM> a=b=c
TJM> a\=b=c
TJM> a\\=b=c
TJM> a\\\=b=c
TJM> ----------------------------

I was thinking of a similar solution, but adding 256 (or some other
large number) to each escaped character (in case there's a '&backslash;'
in the data).  As long as it's valid Unicode and the original data
doesn't contain Unicode characters it should be a clean translation.

Ted


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

Date: Wed, 05 Nov 2008 07:43:05 -0500
From: zentara <zentara@highstream.net>
Subject: Re: ImageMagick: Writing image with 4 colors and palette
Message-Id: <ac43h4hg005glc0chmdi7pva4bs52oegng@4ax.com>

On Tue, 04 Nov 2008 13:53:57 +0100, Josef Moellers
<josef.moellers@fujitsu-siemens.com> wrote:

>zentara wrote:
>> On Mon, 03 Nov 2008 16:12:55 +0100, Josef Moellers
>> <josef.moellers@fujitsu-siemens.com> wrote:
>> 
>> 
>>> It seems that it has to do with the fact that I have a transparent 
>>> background ...
>> 
>> Guess to remove layer:
>> Try adding the flatten option.
>
>I've tried to call $img->Flatten() and $img->Layers(method => 
>'flatten'), none of which worked.
>
>Josef

This worked for me:
tig.png is a green curve on a transparent alpha layer

tig.png PNG 32x32 32x32+0+0 8-bit DirectClass 5.4e+02b 
#after script is run
tig-4c.png PNG 32x32 32x32+0+0 8-bit PseudoClass 4c 3e+02b

#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
use MIME::Base64;

# tig.png is a green curve written on a transparent layer
# included here so we are on same page
my $blob = decode_base64(
'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAAsTAAALEwEAmpwYAAABwUlEQVRYw+2VvS8EURTFf8/4CKJQTKOgEIlEqFCIRnSUhE6iUOhV
Go3Kf0ChkiipNWqFQuErEtFJSEREfO7O0dyNid2Z3X3sbmHfy82bdzPv3TPnnnvHSaKWo4EajzqA
OoBGn0MOl+cT+l8pmANugEdb53wBuHIbkdGfAYKYOws0+qTBl4GgyL5ehhUHcFVkX3ERfm9jraAq
IrQgLmbewX+TghcgsvKLAFVbA895xFQLgMOFQHstq2ACaMnD5TsklWyIEPGMiFDe3C7nrpyVy8AI
0JaQ81mHO3C4oJIp2E0R3TswBKxWJAWIW6M+W4D+LOLd7BaxWPq9xQP3I64teITIxAIvIc7t+dPW
N8QdIvwrAKex4PG5guhAjMd8T8bCh4m13wuAqX0H8ZCg+GlEA6IV0YZYLvBOZKycIcaSADhJuebS
B0wCvcAUECbIZgC4AJqAZhNfaNWxA4wWOBMBl8AecAIc2n/lHsQ8Yh9xYvQlzW3EIKIZ0fKDsU7z
dyO2TANKYCWyFB0jZkgJmJsZxIZRHqRoBYQzG0AclXD3axqAF8SaT3czED2ILsRmKoQCrjvEQtrX
egAKEMOI9R9lHH0BkYPO/OE8jeIAAAAASUVORK5CYII=');

my $img = Image::Magick->new(magick=>'png');
$img->BlobToImage( $blob );
$img->Write('tig.png');

$img->Quantize( colors => 4 );
$img->Set( type => 'Palette' );
$img->Write("tig-4c.png");
__END__

I'm using IM-6.4.3

Maybe your libpng is defective?

zentara



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

Date: Wed, 5 Nov 2008 04:47:06 -0800 (PST)
From: david <michaelgang@gmail.com>
Subject: perl maximum memory
Message-Id: <33c0de12-1eaa-4b9d-9bd4-c48c9de390d6@d36g2000prf.googlegroups.com>

Hi all,

Is there a maximum memory limit for a perl process ?
Is there a difference between 32 and 64 bit perl ?

Thanks,
David


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

Date: Wed, 5 Nov 2008 14:58:43 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: perl maximum memory
Message-Id: <slrngh39kn.819.hjp-usenet2@hrunkner.hjp.at>

On 2008-11-05 12:47, david <michaelgang@gmail.com> wrote:
> Is there a maximum memory limit for a perl process ?

The same as for any other process.

> Is there a difference between 32 and 64 bit perl ?

Yes.

32-bit processes are limited to 4 GB (theoretically, in
practice the limit is more likely to be 2 GB (Linux/i386 is rather weird
with a 3 GB limit)).

For 64-bit processes the limit is theoretically 16 Exabytes, but that's
well beyond the capabilities of current hardware. 

	hp


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

Date: Wed, 05 Nov 2008 08:48:05 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Perl Presentation
Message-Id: <86r65qmgh6.fsf@mithril.chromatico.net>

>>>>> "bdf" == brian d foy <brian.d.foy@gmail.com> writes:

    bdf> In article <868wrzo3x6.fsf@mithril.chromatico.net>, Charlton
    bdf> Wilbur <cwilbur@chromatico.net> wrote:

    >>>>> "cc" == cartercc  <cartercc@gmail.com> writes:
    
    cc> I also have an advanced degree in SW and will finish my PhD in
    cc> SW next year (I hope) and can tell you from experience that Perl
    cc> and academics do not mix.

    >> I expect the numerous academics who actually use Perl (Damian
    >> Conway, for one)

    bdf> Damian's Dead Languages talk tells you why he wasn't fit for
    bdf> academia and mostly isn't in that world anymore. Be careful
    bdf> what you want to make other people say :)

I can't find that talk online, but in the interview he gave at
http://fyi.oreilly.com/2008/08/the-mind-of-damian-conway-scie.html
he offers the explanation that he has too many research interests to
focus on one, which makes university research difficult.

Do not confuse "is a college professor" with "is an academic."

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Wed, 05 Nov 2008 10:10:56 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Perl Presentation
Message-Id: <863ai6qhkf.fsf@lifelogs.com>

On Wed, 05 Nov 2008 08:48:05 -0500 Charlton Wilbur <cwilbur@chromatico.net> wrote: 

CW> Do not confuse "is a college professor" with "is an academic."

I would never.  One is a noun used as an adjective followed by a noun,
the other is an adjective used as a noun.  How could you confuse them?

Ted


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

Date: Wed, 5 Nov 2008 06:23:24 -0800 (PST)
From: yccheok <yancheng.cheok@gmail.com>
Subject: Problem In Setting Up ptkdb for mod_perl
Message-Id: <1a8cff5a-17f5-4d11-a02a-b2f142fd4c6d@d10g2000pra.googlegroups.com>

Hi, I wish to setup a GUI debugging environment for my CGI, which is
running using apache mod_perl

I update the following file (/usr/local/apache_modperl/conf/
httpd.conf) to the below content :-

### Start to hack by Cheok
<Perl>
    use Apache::DB();
    Apache::DB->init;
</Perl>
<Location />
    PerlFixupHandler Apache::DB
</Location>
### End to hack by Cheok

and the following file (/usr/local/lib/perl/5.8.8/Apache/DB.pm)

       if (!$loaded_db) {
           # Fallback
           # require 'Apache/perl5db.pl';
           # Hacked by Cheok
           require Devel::ptkdb;
       }

When I launch a web site, I get the following error log :-

[yanchengdev] [modperl] Prototype mismatch: sub CORE::GLOBAL::exit:
none vs (;$) at /usr/local/lib/perl/5.8.8/Tk.pm line 414. [failed]
[Connection refused]
[yanchengdev] [modperl] [Wed Nov  5 10:48:53 2008] [notice] child pid
15698 exit signal Segmentation fault (11) [success]
[yanchengdev] [modperl] Prototype mismatch: sub CORE::GLOBAL::exit:
none vs (;$) at /usr/local/lib/perl/5.8.8/Tk.pm line 414. [failed]
[Connection refused]
[yanchengdev] [modperl] [Wed Nov  5 10:48:54 2008] [notice] child pid
15699 exit signal Segmentation fault (11) [success]

Any hint on the problem? Is it because I am editing the wrong files
(httpd.conf and DB.pm). I search through my Linux machine, I get the
following files for DB.pm and httpd.conf

/etc/apache/httpd.conf
/usr/share/apache/default-configs/apache-ssl/httpd.conf
/usr/share/apache/default-configs/apache/httpd.conf
/usr/share/apache/default-configs/apache-perl/httpd.conf
/usr/share/doc/apache/examples/httpd.conf
/usr/local/apache_proxy/conf/httpd.conf
/usr/local/apache_modperl/conf/httpd.conf   <--- I am editing this one

/usr/share/perl5/Locale/Object/DB.pm
/usr/share/perl5/DBIx/Class/DB.pm
/usr/share/perl/5.8.8/DB.pm
/usr/local/lib/perl/5.8.8/Apache/DB.pm      <--- I am editing this one

Thanks!

Cheok


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

Date: Wed, 05 Nov 2008 08:38:45 -0500
From: Mark Seger <Mark.Seger@hp.com>
Subject: Sockets and threads...
Message-Id: <ges7l5$7oi$1@usenet01.boi.hp.com>

I want to open some sockets in one thread and write to them from my main 
process and think this is very doable.  I've been looking around a lot 
for answers to this and I think I've figure it out but would like to 
hear if my thinking is indeed correct:

Sockets are global to the process/threads already and so you don't have 
to pass around file descriptors to make them visible to the main 
process.  I had tried (and failed) to share descriptors and failed 
because they're not simple variables.

Looking at some code snippets it feels like all I need to do is get the 
file number from $descriptor->fileno() and share that.

One way to convert a file number, assuming it's in $fn back to a 
descriptor is the following:

open ($fd, ">&$fn);

and now I can syswrite() to it back in my main code.  At least it seems 
to be working correctly.  Is this indeed the 'preferred' way to do this? 
  Am I missing something?  Is there a better way?

-mark


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

Date: Wed, 05 Nov 2008 11:13:20 -0500
From: zentara <zentara@highstream.net>
Subject: Re: Sockets and threads...
Message-Id: <peh3h4l9307j8pnfg70tjvhcq4107730ul@4ax.com>

On Wed, 05 Nov 2008 08:38:45 -0500, Mark Seger <Mark.Seger@hp.com>
wrote:

>I want to open some sockets in one thread and write to them from my main 
>process and think this is very doable.  I've been looking around a lot 
>for answers to this and I think I've figure it out but would like to 
>hear if my thinking is indeed correct:
>
>Sockets are global to the process/threads already and so you don't have 
>to pass around file descriptors to make them visible to the main 
>process.  I had tried (and failed) to share descriptors and failed 
>because they're not simple variables.
>
>Looking at some code snippets it feels like all I need to do is get the 
>file number from $descriptor->fileno() and share that.
>
>One way to convert a file number, assuming it's in $fn back to a 
>descriptor is the following:
>
>open ($fd, ">&$fn);
>
>and now I can syswrite() to it back in my main code.  At least it seems 
>to be working correctly.  Is this indeed the 'preferred' way to do this? 
>  Am I missing something?  Is there a better way?
>
>-mark

Sharing filhandles thru the fileno is the way to go with threads.

See http://perlmonks.org?node_id=662931

for some ideas.

zentara



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

Date: 05 Nov 2008 18:03:39 GMT
From: xhoster@gmail.com
Subject: Re: Sockets and threads...
Message-Id: <20081105130412.455$YO@newsreader.com>

Mark Seger <Mark.Seger@hp.com> wrote:
> I want to open some sockets in one thread and write to them from my main
> process and think this is very doable.

Open a socket to what?  Are you opening sockets "internally" from one
thread to another within the same process?  Is the "open" doing the accept,
or the connect?

> I've been looking around a lot
> for answers to this and I think I've figure it out but would like to
> hear if my thinking is indeed correct:
>
> Sockets are global to the process/threads already and so you don't have
> to pass around file descriptors to make them visible to the main
> process.  I had tried (and failed) to share descriptors and failed
> because they're not simple variables.

Can you show code to illustrate this problem?

> Looking at some code snippets it feels like all I need to do is get the
> file number from $descriptor->fileno() and share that.
>
> One way to convert a file number, assuming it's in $fn back to a
> descriptor is the following:
>
> open ($fd, ">&$fn);

That only works if you only need to write on the socket.  I can't
figure out how to open if you need both read and write.

> and now I can syswrite() to it back in my main code.  At least it seems
> to be working correctly.  Is this indeed the 'preferred' way to do this?
>   Am I missing something?  Is there a better way?

In most cases I can dream up in which I might want to use this, I suspect
I'd prefer to arrange the code differently in the first place.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

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 V11 Issue 1965
***************************************


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