[27957] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9321 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 20 09:05:38 2006

Date: Tue, 20 Jun 2006 06:05:05 -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, 20 Jun 2006     Volume: 10 Number: 9321

Today's topics:
    Re: Embperl and mod_perl support <peace.is.our.profession@gmx.de>
    Re: fork messing up parent filehandle <hjp-usenet2@hjp.at>
        How to write matching pattern for multi-line HTML tag ? <saurabh.sangfroid@gmail.com>
    Re: OO Perl help for a dot Net convert? <siegel@zrz.tu-berlin.de>
    Re: OO Perl help for a dot Net convert? <hjp-usenet2@hjp.at>
    Re: OO Perl help for a dot Net convert? <daveandniki@ntlworld.com>
    Re: OO Perl help for a dot Net convert? <siegel@zrz.tu-berlin.de>
    Re: question on printing to /dev/lp <"v.niekerk at hccnet.nl">
    Re: question on printing to /dev/lp <benmorrow@tiscali.co.uk>
    Re: two servers listening on same port ? <ThomasKratz@REMOVEwebCAPS.de>
    Re: two servers listening on same port ? <sisyphus1@nomail.afraid.org>
    Re: two servers listening on same port ? <siegel@zrz.tu-berlin.de>
    Re: two servers listening on same port ? sc_wizard29@hotmail.com
    Re: two servers listening on same port ? <sisyphus1@nomail.afraid.org>
    Re: two servers listening on same port ? <ThomasKratz@REMOVEwebCAPS.de>
    Re: two servers listening on same port ? <benmorrow@tiscali.co.uk>
    Re: two servers listening on same port ? <benmorrow@tiscali.co.uk>
    Re: two servers listening on same port ? <benmorrow@tiscali.co.uk>
    Re: two servers listening on same port ? <noreply@gunnar.cc>
    Re: What is Expressiveness in a Computer Language <rossberg@ps.uni-sb.de>
        What's ^$ mean? <zhushenli@gmail.com>
    Re: What's ^$ mean? <peace.is.our.profession@gmx.de>
    Re: What's ^$ mean? <peace.is.our.profession@gmx.de>
    Re: What's ^$ mean? <mol10metal@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 20 Jun 2006 12:22:54 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: Embperl and mod_perl support
Message-Id: <e78igr$c29$1@mlucom4.urz.uni-halle.de>

Thus spoke Hobo Salesman (on 2006-06-20 03:34):

> How widely is mod_perl and Embperl supported by web hosts? I have to
> develop a web application that needs to be portable among web hosts. I
> want to use Perl, but only if I can use Embperl/mod_perl. My other
> optin is PHP5, very widely supported and a little easier/faster, but
> seems kind of like driving a volvo when theres a ferrari in the garage.

No, its rather like
"driving a Toyota Pickup when theres a HMMVEE in the garage"

(you need a lot of fuel and expertise for the latter,
but can win the war with it ;-)

> Portability is a big issue though, having a client's webhost say they
> require payment for a dedicated server to use Embperl would be.... bad.

In my country, you almost everywhere have
the Toyota pre-installed on budget websites,
and need to choose among the more expensive
ones for the HMMVEE.

Another pick would be a 'virtual server' site,
where you are 'root' and may install whatever
you want (including apache/mod_perl AND mod_php
the same time).

How much $$ would you like to spend
every month? That's what you get then ;-)

Regards

Mirco


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

Date: Tue, 20 Jun 2006 13:51:24 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: fork messing up parent filehandle
Message-Id: <tfn87e.jev.ln@teal.hjp.at>

darksaga wrote:
> problem is that the fork command seems to mess up the parent filehandle
> to my file, altough the children do not use this filehandle. when
> looping through the file, the filehandle is magically reset to the
> beginning of the file, or a position near the beginning. (see code
> below)

Just for the record. I cannot replicate your problem on perl 5.8.4 on
Linux. The program prints:

----8<-------8<-------8<-------8<-------8<-------8<-------8<-------8<---
initial child spawning...
1
2
3
4
5
6
7
8
9
10
initial child spawning done...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
readline() on closed filehandle GEN0 at /usr/lib/perl/5.8/IO/Handle.pm line 1
readline() on closed filehandle GEN0 at /usr/lib/perl/5.8/IO/Handle.pm line 1
readline() on closed filehandle GEN0 at /usr/lib/perl/5.8/IO/Handle.pm line 1
readline() on closed filehandle GEN0 at /usr/lib/perl/5.8/IO/Handle.pm line 1
readline() on closed filehandle GEN0 at /usr/lib/perl/5.8/IO/Handle.pm line 1
readline() on closed filehandle GEN0 at /usr/lib/perl/5.8/IO/Handle.pm line 1
readline() on closed filehandle GEN0 at /usr/lib/perl/5.8/IO/Handle.pm line 1
readline() on closed filehandle GEN0 at /usr/lib/perl/5.8/IO/Handle.pm line 1
all child processes are finished...
wait() says no more children...
parent is done...
----8<-------8<-------8<-------8<-------8<-------8<-------8<-------8<---
which is what I expected. If you expected some different output, please
specify what you expected.

(I noticed a few other problems with your program - but they don't seem
to be related to the problem you describe, so I guess they are caused by
cutting down a real program down to a minimal test case)

        hp

-- 
   _  | Peter J. Holzer    | Man könnte sich [die Diskussion] auch
|_|_) | Sysadmin WSR/LUGA  | sparen, wenn man sie sich einfach sparen
| |   | hjp@hjp.at         | würde.
__/   | http://www.hjp.at/ |   -- Ralph Angenendt in dang 2006-04-15


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

Date: 20 Jun 2006 05:49:34 -0700
From: "Saurabh" <saurabh.sangfroid@gmail.com>
Subject: How to write matching pattern for multi-line HTML tag ?
Message-Id: <1150807774.180161.245720@c74g2000cwc.googlegroups.com>

Hi,

I want to create a pattern to remove the tags from a HTML source file.
But the pattern I have created does not handle the multiline tags. Is
there any way to handle the tags spanning over more than one line in
following pattern ?

                           s!\<(\!\|\/)?.*?(\/)?\>!!gix


Thanks in advance.

Regards
Saurabh.



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

Date: Tue, 20 Jun 2006 13:26:05 +0200
From: Anno Siegel <siegel@zrz.tu-berlin.de>
Subject: Re: OO Perl help for a dot Net convert?
Message-Id: <4fq4dmF1k6d75U1@news.dfncis.de>

ben.wilder@gmail.com wrote:

> Hello all,
> 
> I am making the transition from .Net to Perl for a new project and i
> have a few questions about OO Perl, that i would be most grateful if
> someone could comment on / answer!
> 
> Many thanks for any of your help,
> 
> 
> This problem is conceptual, in that i am waiting to learn about certain
> features before trying to actually implement this - so i'll put
> together a dummy OO module and a calling script.
> 
>
------------------------------------------------------------------------------------------
> ****************
> * Perl Module  *
> ****************
> package MyPackage;
> 
> 
> #Use definitions
> use strict;
> 
> 
> #Contructor for MyPackage Class
> sub new {
>   my ($class, %arg) = @_;
>   bless {
>         _myFirstName          =>      $arg{myFirstName},
>         _myLastName           =>      $arg{myLastName},
> _myAge                        =>      $arg{myAge},
> _myFavouriteArtists   =>      $arg{myFavouriteArtists},

Better:

    _myFavouriteArtists => [ @{ $arg{myFavouriteArtists} } ],

to decouple the original array (see below).

>   }, $class;
> }
> 
> 
> sub ShowAgeAndArtists{
> 
> my $self = $_[0];
> 
> #Dereference array
> my @myFavouriteArtists = @{$self->{_myFavouriteArtists}};

Copying the array is not necessary here, you're not changing it.

> my $artist = '';
> 
> foreach $artist ( @myFavouriteArtists )

Just say

   foreach $artist ( @{ $self->{ _myFavouriteArtists} } ) {

> {
> print "$self->{_myFirstName} aged  $self->{_myAge}, likes $artist\n";
> }
> 
> 
> }
> 
> 1;
>
------------------------------------------------------------------------------------------
> 
> 
>
------------------------------------------------------------------------------------------
> ********************
> *  Calling script  *
> ********************
> #!/usr/bin/perl -w
> 
> use strict;
> use MyPackage;
> 
> my $myFirstName = 'Ben';
> my $myLastName = 'Wilder';
> my $myAge = 28;
> my @myFavouriteArtists = qw[Wolfmother LedZep ChesneyHawkes];
> 
> #Instantiate MyPackage class
> my $myPackage =
>
MyPackage->new(myFirstName=>$myFirstName,myLastName=>$myLastName,myAge=>$myAge,myFavouriteArtists=>\@myFavouriteArtists);
> 
> $myPackage->ShowAgeAndArtists();
> 
>
------------------------------------------------------------------------------------------
> 
> Now that i have my example, i'd like to ask a few questions:
> 
> 1. I am passing a reference to the @myFavouriteArtists array, however
> with objects being in my mind, an encapsulation of data, it this the
> most effective way to pass array data to an object? Can i pass the data
> by value so that the object deals with its own copy of the data - or am
> i being silly?

No, not at all.  Storing a reference to the @myFavouriteArtists array
means that later changes to that array will be reflected in the
object -- usually not what you want.  To avoid this, make a copy
of the array when you initialize the object (see code above).  On
the other hand you're copying the array on access, which is not
necessary.

> 
> 2. In MS .Net there is the principle of object fields, object instance
> scoped, not class scoped, that are not accessible through any public
> methods, but are used possibly by methods private to the class. For
> example - in the above scenario i may want to implement a boolean flag
> "IsTooOld" that can be set by a private internal method for the
> purposes of a logical decision elsewhere in the module. How can i
> define such a variable in perl? It seems that since i am blessing the
> hash into object-hood, that is where i will have to put the definition,
> but i dont want the constructor to be able to alter this definition!
> Any ideas (please let me know if i havent put explained this well
> enough!)

There is no concept of private methods in Perl OO.  Instead we use the
simple convention that methods whose names start with an underscore
are meant to be private and the class user is not supposed to call
them directly.  This is not enforcable, however.

Two more remarks:

It is usually better to have a separate initializer method (->init, say)
in each class that takes a given object and sets it up for use with
that class.  The conventional ->new method can then be written:

    sub new {
        my $class = shift;
        bless( {}, $class)->init( @_);

This separation is not usually taught with Perl OO, but it is
nevertheless important.  It is hard to set up objects for multiple
inheritance without it.

You have chosen the common implementation of Perl objects as hashrefs.
It may be worth while to acquaint yourself with the concept of inside-out
classes.  These are a relatively newly developed alternative to more
conventional ways of implementing objects in Perl.  Inside-out classes
are a little more involved than other types of classes, but give you
a class that can be inherited by *any* other Perl class, whether it
is itself inside-out or not.  Normal classes are usually confined in
inheritance to classes of the same type (hash in your case), or else...
Google for "inside-out Perl" with an eye to articles on perlmonks.

Anno


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

Date: Tue, 20 Jun 2006 13:28:47 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: OO Perl help for a dot Net convert?
Message-Id: <f5m87e.68v.ln@teal.hjp.at>

ben.wilder@gmail.com wrote:
[ example snipped]
> Now that i have my example, i'd like to ask a few questions:
> 
> 1. I am passing a reference to the @myFavouriteArtists array, however
> with objects being in my mind, an encapsulation of data, it this the
> most effective way to pass array data to an object? Can i pass the data
> by value so that the object deals with its own copy of the data - or am
> i being silly?

Your constructor needs to distinguish between its arguments. Since there
is exactly one array, you could change your constructor to:

sub new {
  my ($class, $myFirstName, $myLastName, $myAge, @myFavouriteArtists) = @_;
  ...
}

and call it like

MyPackage->new($myFirstName,$myLastName,$myAge,@myFavouriteArtists);

or 

MyPackage->new("Ben","Wilder",28, "Wolfmother", "LedZep", "ChesneyHawkes");

But what happens if you add a second array?

Alternatively, you could scan the @_ in the constructor for keywords
like "myFirstName", "myLastName", etc. But what happens if someone
founds a band called "myAge"?

So I think, passing references to arrays is generally the best way. 

You can of course make a copy of the array in the constructor:

      _myFavouriteArtists     =>      [ @{ $arg{myFavouriteArtists} } ],

if you want to. I found this rarely to be necessary, and usually made
the copy when calling the constructor (because when I'm calling the
constructor, I know whether I will continue to use the array. I don't
know this in the constructor).

> 2. In MS .Net there is the principle of object fields, object instance
> scoped, not class scoped, that are not accessible through any public
> methods, but are used possibly by methods private to the class.

This seems to be a rather strange concept to me. I understand making
fields private so they are only accessible through methods from the
outside. But why make them inaccessible from the inside?

> For example - in the above scenario i may want to implement a boolean
> flag "IsTooOld" that can be set by a private internal method for the
> purposes of a logical decision elsewhere in the module. How can i
> define such a variable in perl?

Perl doesn't even have private methods, much less a way to declare that
some variable should be accessible to only some methods.

It's probably possible to achieve this with tie. Maybe there is even
already a package on CPAN which does this. (There are a lot of packages
on CPAN implementing different styles of object oriented programming -
I've played with a few but always went back to the basic blessed hashref
style).

> It seems that since i am blessing the hash into object-hood, that is
> where i will have to put the definition, but i dont want the
> constructor to be able to alter this definition!

In the blessed hashref style, there is no information hiding at all. Not
only can the constructor change the object (well it has to, since it
*creates* the object in the first place), but anybody who gets the
object can examine and change its contents - it is just a hashref, after
all.

        hp

-- 
   _  | Peter J. Holzer    | Man könnte sich [die Diskussion] auch
|_|_) | Sysadmin WSR/LUGA  | sparen, wenn man sie sich einfach sparen
| |   | hjp@hjp.at         | würde.
__/   | http://www.hjp.at/ |   -- Ralph Angenendt in dang 2006-04-15


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

Date: Tue, 20 Jun 2006 13:56:24 +0200
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: OO Perl help for a dot Net convert?
Message-Id: <4497e272$0$1025$ba4acef3@news.orange.fr>


<ben.wilder@gmail.com> wrote in message 
news:1150794749.421759.108400@h76g2000cwa.googlegroups.com...
> Hello all,
>
> I am making the transition from .Net to Perl for a new project and i
> have a few questions about OO Perl, that i would be most grateful if
> someone could comment on / answer!
>
> Many thanks for any of your help,
>
>
> This problem is conceptual, in that i am waiting to learn about certain
> features before trying to actually implement this - so i'll put
> together a dummy OO module and a calling script.
>
> ------------------------------------------------------------------------------------------
> ****************
> * Perl Module  *
> ****************
> package MyPackage;
>
>
> #Use definitions
> use strict;
>
>
> #Contructor for MyPackage Class
> sub new {
>  my ($class, %arg) = @_;
>  bless {
>        _myFirstName => $arg{myFirstName},
>        _myLastName => $arg{myLastName},
> _myAge => $arg{myAge},
> _myFavouriteArtists => $arg{myFavouriteArtists},
>  }, $class;
> }
>
>
> sub ShowAgeAndArtists{
>
> my $self = $_[0];
>
> #Dereference array
> my @myFavouriteArtists = @{$self->{_myFavouriteArtists}};
>
> my $artist = '';
>
> foreach $artist ( @myFavouriteArtists )
> {
> print "$self->{_myFirstName} aged  $self->{_myAge}, likes $artist\n";
> }
>
>
> }
>
> 1;
> ------------------------------------------------------------------------------------------
>
>
> ------------------------------------------------------------------------------------------
> ********************
> *  Calling script  *
> ********************
> #!/usr/bin/perl -w
>
> use strict;
> use MyPackage;
>
> my $myFirstName = 'Ben';
> my $myLastName = 'Wilder';
> my $myAge = 28;
> my @myFavouriteArtists = qw[Wolfmother LedZep ChesneyHawkes];
>
> #Instantiate MyPackage class
> my $myPackage =
> MyPackage->new(myFirstName=>$myFirstName,myLastName=>$myLastName,myAge=>$myAge,myFavouriteArtists=>\@myFavouriteArtists);
>
> $myPackage->ShowAgeAndArtists();
>
> ------------------------------------------------------------------------------------------
>
> Now that i have my example, i'd like to ask a few questions:
>
> 1. I am passing a reference to the @myFavouriteArtists array, however
> with objects being in my mind, an encapsulation of data, it this the
> most effective way to pass array data to an object? Can i pass the data
> by value so that the object deals with its own copy of the data - or am
> i being silly?
>
>
> 2. In MS .Net there is the principle of object fields, object instance
> scoped, not class scoped, that are not accessible through any public
> methods, but are used possibly by methods private to the class. For
> example - in the above scenario i may want to implement a boolean flag
> "IsTooOld" that can be set by a private internal method for the
> purposes of a logical decision elsewhere in the module. How can i
> define such a variable in perl? It seems that since i am blessing the
> hash into object-hood, that is where i will have to put the definition,
> but i dont want the constructor to be able to alter this definition!
> Any ideas (please let me know if i havent put explained this well
> enough!)
>
>
> Thanks again for any help!
>
> Now go easy on the perl noob guys *backs into corner*
>
>
> Ben
>

You should have a look at Conway's 'Perl Best Practices' that has some 
strong advise about how to implement OO Perl. It goes without saying that 
this advice is not universally accepted in the Perl community but it is 
worth considering nontheless. [I believe Schwarz's 'Intermediate Perl' has 
different OO Perl recommendations but I have not read that one].

Dave




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

Date: Tue, 20 Jun 2006 14:15:29 +0200
From: Anno Siegel <siegel@zrz.tu-berlin.de>
Subject: Re: OO Perl help for a dot Net convert?
Message-Id: <4fq7aaF1jjvlcU1@news.dfncis.de>

Peter J. Holzer wrote:
> ben.wilder@gmail.com wrote:

[snippage]

> So I think, passing references to arrays is generally the best way.
> 
> You can of course make a copy of the array in the constructor:
> 
>       _myFavouriteArtists     =>      [ @{ $arg{myFavouriteArtists} } ],
> 
> if you want to. I found this rarely to be necessary,

It is practically always necessary to copy any references before
using them in an object.  Just consider a loop like this:

    while ( <> ) {
        my ( $first, $last, $age, @artists) = split;
        push @somewhere, MyPackage->new( $first, $last, $age, \ @artists);
    }

All the objects created in this loop will *share* their internal
myFavouriteArtists array and will show the same favourite artists
unless you copy the array on object creation.

Anno



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

Date: Tue, 20 Jun 2006 14:15:33 +0200
From: Huub <"v.niekerk at hccnet.nl">
Subject: Re: question on printing to /dev/lp
Message-Id: <4497e6e4$0$3144$e4fe514c@dreader13.news.xs4all.nl>

> 
> The usual way to print on Unix systems is to open a pipe to lpr(1) or
> lp(1) (depending on which you have). Read the manual to find out what
> data formats they accept: commonly, you must convert your output to
> PostScript. You can do this with the program a2ps (among others); this
> will convert a form-feed ("\cL") into a new page.
> 
> Ben
> 

Sorry, but I don't fully understand it. You're mentioning pipe, but when 
I read "man perlfunc", it seems there's no way to really print to a 
(network)printer from the script. As I understand I have to print to 
file first, and then to a printer. Is this correct?


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

Date: Tue, 20 Jun 2006 13:50:01 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: question on printing to /dev/lp
Message-Id: <pg7lm3-1oo.ln1@osiris.mauzo.dyndns.org>


Quoth Huub <"v.niekerk at hccnet.nl">:
<benmorrow@tiscali.co.uk> wrote:

[ please attribute quotations ]

> > The usual way to print on Unix systems is to open a pipe to lpr(1) or
> > lp(1) (depending on which you have). Read the manual to find out what
> > data formats they accept: commonly, you must convert your output to
> > PostScript. You can do this with the program a2ps (among others); this
> > will convert a form-feed ("\cL") into a new page.
> 
> Sorry, but I don't fully understand it. You're mentioning pipe, but when 
> I read "man perlfunc", it seems there's no way to really print to a 
> (network)printer from the script. As I understand I have to print to 
> file first, and then to a printer. Is this correct?

No. You have to open a pipe lpr(1) or lp(1). If you don't understand
this statement you need to find out more about how your OS works before
you try programming for it; and, as I said, you need to find out what
data formats your print spooler will accept.

Ben

-- 
I touch the fire and it freezes me,               [benmorrow@tiscali.co.uk]
I look into it and it's black.
Why can't I feel? My skin should crack and peel---
I want the fire back...                     Buffy, 'Once More With Feeling'


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

Date: Tue, 20 Jun 2006 12:57:22 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: two servers listening on same port ?
Message-Id: <4497d492$0$31172$bb690d87@news.main-rheiner.de>

sc_wizard29@hotmail.com wrote:
> hi everyone,
> 
> This ones makes me scratch my head : I'm using the following script on
> Windows and it looks like I can run two instances of it
> simultaneously...which means that I have 2 servers listening on the
> same port.
> 
>  #!/usr/bin/perl -w
> use strict;
> use Socket;
> my $port = 8080;
> my $proto = getprotobyname('tcp');
> socket(Server, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
> setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1))  || die
> "setsockopt: $!";

Get rid of the SO_REUSEADDR. IIRC this will have the disadvantage that you 
may have to wait a bit before you can reopen the socket after a close.

> bind(Server, sockaddr_in($port, INADDR_ANY)) || die "bind: $!";
> listen(Server,SOMAXCONN) || die "listen: $!";
> print "Server : server started on port $port\n";
> while(1) {}
> 
> I was expecting an error like "port already in use". Am I doing
> something wrong ?
> 

You might find IO::Socket easier to use.

Thomas

-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


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

Date: Tue, 20 Jun 2006 21:20:03 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: two servers listening on same port ?
Message-Id: <4497dabe$0$25917$afc38c87@news.optusnet.com.au>


"Thomas Kratz" <ThomasKratz@REMOVEwebCAPS.de> wrote in message
 .
 .
>
> You might find IO::Socket easier to use.
>

Yes - that's what *I* use - but it still permits multiple instances of
servers to be listening on the same port.

Seems to be a Win32 thing - on linux I find it's not possible to run
multiple instances of the same server script. I get the fatal error "Address
already in use".

Even with the latest CPAN release of IO, the behaviour persists on Win32.
Should this be submitted as a bug to
http://rt.cpan.org/Public/Dist/Display.html?Name=IO ?

Cheers,
Rob




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

Date: Tue, 20 Jun 2006 13:46:27 +0200
From: Anno Siegel <siegel@zrz.tu-berlin.de>
Subject: Re: two servers listening on same port ?
Message-Id: <4fq5jsF1juqmtU1@news.dfncis.de>

Sisyphus wrote:

> 
> "Anno Siegel" <siegel@zrz.tu-berlin.de> wrote in message
> .
> .
>>
>> > Not sure of the "approved" method for determining whether a port is in
>> > use.
>>
>> As filehandles, sockets are flock-able.  An exclusive lock in the
>> server should do:
>>
>>     flock $server, LOCK_EX | LOCK_NB or die "port in use";
>>
> 
> Also not sure about the use of flock() on Win32. When I insert the above
> code into my server script (which runs with warnings pragma enabled) it
> dies with:
> 
> Argument "LOCK_OZ" isn't numeric in flock at file_server.plx line 35.
> port in use at file_server.plx line 35.

LOCK_OZ? Whazzat?  Some windowy specialty?

> Line 35 is simply the line that implements the above code - the port is
> definitely not in use.
> 
> From 'perldoc -f flock' I find:
> "Produces a fatal error if used on a machine that doesn't implement
> flock(2), fcntl(2) locking, or lockf(3)."
> 
> 'perldoc perlport' reports that fcntl() is not implemented on Win32,
> though flock() *is* implemented ... not sure what to make of all that.

I have no personal experience with Windows, but I thought that file
locking worked.

Anno


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

Date: 20 Jun 2006 05:04:11 -0700
From: sc_wizard29@hotmail.com
Subject: Re: two servers listening on same port ?
Message-Id: <1150805051.456848.88290@p79g2000cwp.googlegroups.com>

Looks like the use of netstat before the binding is the most "direct"
solution...

Here is the same script with IO::Socket (the problem is the same but
the script is shorter ;)

 #!/usr/bin/perl -w
use strict;
use IO::Socket;
my $port=8080;
my $server = IO::Socket::INET->new(Proto     => 'tcp',
                                   LocalPort => $port,
                                   Listen    => SOMAXCONN,
                                   Reuse     => 1);
die "can't setup server" unless $server;
print "Server : server started on port $port\n";
while(1) {}



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

Date: Tue, 20 Jun 2006 22:20:03 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: two servers listening on same port ?
Message-Id: <4497e8ce$0$22364$afc38c87@news.optusnet.com.au>


"Anno Siegel" <siegel@zrz.tu-berlin.de> wrote in message
 .
 .
>
> LOCK_OZ? Whazzat?  Some windowy specialty?
>

or maybe an Aussie specialty  :-)

>
> I have no personal experience with Windows, but I thought that file
> locking worked.
>

Heh ... I had this notion that it worked on Win32 without even being
specifically invoked :-)

Btw, I (inadvertently) omitted some relevant info from my reply - if I run
under strictures I get:

Bareword "LOCK_EX" not allowed while "strict subs" in use at file_server.plx
line 35.
Bareword "LOCK_NB" not allowed while "strict subs" in use at file_server.plx
line 35.

Without strictures the error is as I reported.

I tried not supplying a second argument, but perl insists that a second arg
be supplied. I'm not feeling very energetic about this at the moment ....
maybe later :-)

Cheers,
Rob




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

Date: Tue, 20 Jun 2006 14:27:35 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: two servers listening on same port ?
Message-Id: <4497e9b6$0$31170$bb690d87@news.main-rheiner.de>

Sisyphus wrote:
> "Thomas Kratz" <ThomasKratz@REMOVEwebCAPS.de> wrote in message
> .
> .
> 
>>You might find IO::Socket easier to use.
>>
> 
> 
> Yes - that's what *I* use - but it still permits multiple instances of
> servers to be listening on the same port.

No to me it does not. Using:

  my $srv = IO::Socket::INET->new(
       Proto => 'tcp',
       LocalPort => 4016,
       Listen => SOMAXCONN,
       ReuseAddr => 0,
  );

the second instance fails reporting 'Unknown error' ($!).

> 
> Seems to be a Win32 thing - on linux I find it's not possible to run
> multiple instances of the same server script. I get the fatal error "Address
> already in use".

In Winsock 2 there is a new socket option called SO_EXCLUSIVEADDRUSE.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/using_so_exclusiveaddruse.asp

> 
> Even with the latest CPAN release of IO, the behaviour persists on Win32.
> Should this be submitted as a bug to
> http://rt.cpan.org/Public/Dist/Display.html?Name=IO ?

I don't think it's a bug. More a winsock "feature".

Thomas


-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


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

Date: Tue, 20 Jun 2006 13:15:51 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: two servers listening on same port ?
Message-Id: <ng5lm3-4go.ln1@osiris.mauzo.dyndns.org>


Quoth siegel@zrz.tu-berlin.de:
> Sisyphus wrote:
> 
> > 
> > <sc_wizard29@hotmail.com> wrote in message
> > news:1150748276.735336.108720@p79g2000cwp.googlegroups.com...
> >> hi everyone,
> >>
> >> This ones makes me scratch my head : I'm using the following script on
> >> Windows and it looks like I can run two instances of it
> >> simultaneously...which means that I have 2 servers listening on the
> >> same port.
> 
> [...]
> 
> > Not sure of the "approved" method for determining whether a port is in
> > use.
> 
> As filehandles, sockets are flock-able.

I *seriously* doubt if they are on Win32. Sockets on Win32 are not
ordinary filehandles, perl just fakes them up to look like it.

To the OP: remove the SO_REUSEADDR. Winsock is *COMPLETELY* broken;
among other things, SO_REUSEADDR doesn't mean 'allow another process to
bind again after the socket is closed but before the wait period' but
actually means 'bind to this port even if there is another process bound
there, at which point both sockets become non-deterministic' !!

See http://msdn.microsoft.com/library/default.asp?url=/library/en-us
    /winsock/winsock/using_so_reuseaddr_and_so_exclusiveaddruse.asp

(please excuse the wrapping).

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
                                                        benmorrow@tiscali.co.uk


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

Date: Tue, 20 Jun 2006 13:41:59 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: two servers listening on same port ?
Message-Id: <n17lm3-1oo.ln1@osiris.mauzo.dyndns.org>


Quoth sc_wizard29@hotmail.com:
> Looks like the use of netstat before the binding is the most "direct"
> solution...

No, omit the SO_REUSEADDR...

> Here is the same script with IO::Socket (the problem is the same but
> the script is shorter ;)
> 
>  #!/usr/bin/perl -w
> use strict;
> use IO::Socket;
> my $port=8080;
> my $server = IO::Socket::INET->new(Proto     => 'tcp',
>                                    LocalPort => $port,
>                                    Listen    => SOMAXCONN,
>                                    Reuse     => 1);
                                     ^^^^^^^^^^^^^^
 ...or this.

Ben

-- 
           All persons, living or dead, are entirely coincidental.
benmorrow@tiscali.co.uk                                           Kurt Vonnegut


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

Date: Tue, 20 Jun 2006 13:46:27 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: two servers listening on same port ?
Message-Id: <3a7lm3-1oo.ln1@osiris.mauzo.dyndns.org>


Quoth "Sisyphus" <sisyphus1@nomail.afraid.org>:
> 
> "Anno Siegel" <siegel@zrz.tu-berlin.de> wrote in message
> .
> > LOCK_OZ? Whazzat?  Some windowy specialty?
> 
> or maybe an Aussie specialty  :-)
> 
> > I have no personal experience with Windows, but I thought that file
> > locking worked.
> 
> Heh ... I had this notion that it worked on Win32 without even being
> specifically invoked :-)

Opening a file takes a mandatory lock, unless you ask it not to.

> Btw, I (inadvertently) omitted some relevant info from my reply - if I run
> under strictures I get:
> 
> Bareword "LOCK_EX" not allowed while "strict subs" in use at file_server.plx
> line 35.
> Bareword "LOCK_NB" not allowed while "strict subs" in use at file_server.plx
> line 35.
> 
> Without strictures the error is as I reported.

<giggle>

If you don't import those constants from the Fcntl module, then Perl
(without strict) will treat them as unquoted strings. Then we have

~% perl -le'print "LOCK_EX" | "LOCK_NB"'
LOCK_OZ

Have you *really* never used flock before?

Ben

-- 
Giles: It's very common for Indian spirits to change to animal form.
Buffy: [...] and, 'Native American'. G: Sorry? B: We don't say 'Indian'.
G: Oh, right, yes; always behind on the terms... yes, still trying not to refer
to you lot as 'bloody colonials'.      [Buffy, 'Pangs'] benmorrow@tiscali.co.uk


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

Date: Tue, 20 Jun 2006 14:58:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: two servers listening on same port ?
Message-Id: <4fq9qqF1j7cpiU1@individual.net>

Anno Siegel wrote:
> I have no personal experience with Windows, but I thought that file
> locking worked.

IIRC, flock() causes a fatal error on Windows 95/98, but works on later 
Windows versions.

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


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

Date: Tue, 20 Jun 2006 14:01:20 +0200
From: Andreas Rossberg <rossberg@ps.uni-sb.de>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <e78o2g$8usvs$2@hades.rz.uni-saarland.de>

Rob Thorpe wrote:
> 
> No, that isn't what I said.  What I said was:
> "A language is latently typed if a value has a property - called it's
> type - attached to it, and given it's type it can only represent values
> defined by a certain class."

"it [= a value] [...] can [...] represent values"?

> Easy, any statically typed language is not latently typed.  Values have
> no type associated with them, instead variables have types.

A (static) type system assigns types to (all) *expressions*. This 
includes values as well as variables.

Don't confuse type assignment with type annotation (which many 
mainstream languages enforce for, but also only allow for, variable 
declarations).

- Andreas


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

Date: 20 Jun 2006 04:14:05 -0700
From: "Davy" <zhushenli@gmail.com>
Subject: What's ^$ mean?
Message-Id: <1150802045.764523.158360@g10g2000cwb.googlegroups.com>

Hi,

Is ^$ mean a NULL line?

Best regards,
Davy



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

Date: Tue, 20 Jun 2006 13:25:29 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: What's ^$ mean?
Message-Id: <e78m65$cuh$1@mlucom4.urz.uni-halle.de>

Thus spoke Davy (on 2006-06-20 13:14):

> Is ^$ mean a NULL line?

No, its usually used for detection of
"lines with no characters in them"
(only the logical line feed \n is there)
in /m mode of a regex.


Regards

Mirco


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

Date: Tue, 20 Jun 2006 13:35:12 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: What's ^$ mean?
Message-Id: <e78moc$d85$1@mlucom4.urz.uni-halle.de>

Thus spoke Mirco Wahab (on 2006-06-20 13:25):

> "lines with no characters in them"

A made up example of how you would use it:


use strict;
use warnings;

my $count = 0;
my $text= <<END_OF_TEXT;
A Line with something in it


two empty lines above!
(done)
END_OF_TEXT

print "empty line " . ++$count . " found\n"
   for $text =~ /^$/gm;      # <== here we go



Regards

Mirco



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

Date: 20 Jun 2006 05:53:34 -0700
From: "Nick of course" <mol10metal@hotmail.com>
Subject: Re: What's ^$ mean?
Message-Id: <1150808014.840927.250240@h76g2000cwa.googlegroups.com>


Mirco Wahab wrote:
> Thus spoke Mirco Wahab (on 2006-06-20 13:25):
>
> > "lines with no characters in them"
>
> A made up example of how you would use it:
>
>
> use strict;
> use warnings;
>
> my $count = 0;
> my $text= <<END_OF_TEXT;
> A Line with something in it
>
>
> two empty lines above!
> (done)
> END_OF_TEXT
>
> print "empty line " . ++$count . " found\n"
>    for $text =~ /^$/gm;      # <== here we go
>
>
>
> Regards
>
> Mirco
A slightly shorter answer to the original question would have been "Yes"



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

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 9321
***************************************


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