[19976] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2171 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 21 11:05:32 2001

Date: Wed, 21 Nov 2001 08:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006358709-v10-i2171@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 21 Nov 2001     Volume: 10 Number: 2171

Today's topics:
        a beginner (Mario)
        a simple question <Yong.Zhang@marconi.com>
    Re: a simple question <keesh@users-dot-sf.net>
    Re: a simple question <bernard.el-hagin@lido-tech.net>
    Re: a simple question <spam@thecouch.homeip.net>
    Re: a simple question <Tassilo.Parseval@post.rwth-aachen.de>
    Re: a simple question <keesh@users-dot-sf.net>
    Re: a simple question <bernard.el-hagin@lido-tech.net>
    Re: Anyone Read  "Programming the Perl DBI" lately? (Hardy Merrill)
        Bitwise Operators - How to use? <mmanso@yahoo.com>
    Re: Can I avoid 2 passes? (Drew Myers)
    Re: Can I avoid 2 passes? <ellem@techie.net>
    Re: Can I avoid 2 passes? <godzilla@stomp.stomp.tokyo>
    Re: Do Not Redirect CGI Questions To CIWAC <godzilla@stomp.stomp.tokyo>
        File position of of every word in a file (Rob van Strien)
    Re: How to split variable length row <nospam@newsranger.com>
    Re: installing DBD::mysql on linux (John J. Trammell)
    Re: IO::Select and IO::Socket question: multiple connec <spam@thecouch.homeip.net>
    Re: IO::Select and IO::Socket question: multiple connec <dredd@megacity.org>
    Re: IO::Select and IO::Socket question: multiple connec <spam@thecouch.homeip.net>
    Re: IO::Select and IO::Socket question: multiple connec <zoltan.kandi@tellabs.com>
    Re: LWP::UserAgent Post & Session problem (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 21 Nov 2001 07:47:02 -0800
From: fijc2001@yahoo.com (Mario)
Subject: a beginner
Message-Id: <192f48ce.0111210747.148cae71@posting.google.com>

Hi gays
I need to know free good and fast tutorials in the web to learn PERL
in CGI applications
regards


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

Date: Wed, 21 Nov 2001 10:37:26 -0500
From: "Yong Zhang" <Yong.Zhang@marconi.com>
Subject: a simple question
Message-Id: <9tghie$puj$1@newsfeed.pit.comms.marconi.com>

I am not familiar with perl. Can you tell me a easy way to get the stuff
between ( and ) in a sentence. There will be only one ( and ) in the whole
sentence. The sentence looks like:

sadsajkdfskjdfs(kj454sd)errttyyu.

Thanks!






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

Date: Wed, 21 Nov 2001 15:41:54 GMT
From: Ciaran McCreesh <keesh@users-dot-sf.net>
Subject: Re: a simple question
Message-Id: <6XPK7.13769$%j6.1380623@news1.cableinet.net>

Yong Zhang wrote:
> I am not familiar with perl. Can you tell me a easy way to get the stuff
> between ( and ) in a sentence. There will be only one ( and ) in the whole
> sentence. The sentence looks like:
> 
> sadsajkdfskjdfs(kj454sd)errttyyu.

Okay, say the sentence is in $line :

if ($line =~ /(\(.*?\))/) {
  print $1;
} else {
  print "No match.";
}



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

Date: 21 Nov 2001 15:41:14 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: a simple question
Message-Id: <slrn9vnlnn.qsr.bernard.el-hagin@gdndev25.lido-tech>

On Wed, 21 Nov 2001 10:37:26 -0500, Yong Zhang <Yong.Zhang@marconi.com> wrote:
> I am not familiar with perl. Can you tell me a easy way to get the stuff
> between ( and ) in a sentence. There will be only one ( and ) in the whole
> sentence. The sentence looks like:
> 
> sadsajkdfskjdfs(kj454sd)errttyyu.


my $sentence = 'sadsajkdfskjdfs(kj454sd)errttyyu.';
my ($stuff_between_parens) = $sentence =~ m/\(([^)]*)\)/;

print $stuff_between_parens;


Cheers,
Bernard


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

Date: Wed, 21 Nov 2001 10:43:01 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: a simple question
Message-Id: <3YPK7.31720$bA4.1253938@wagner.videotron.net>


"Yong Zhang" <Yong.Zhang@marconi.com> wrote in message
news:9tghie$puj$1@newsfeed.pit.comms.marconi.com...
> I am not familiar with perl. Can you tell me a easy way to get the stuff
> between ( and ) in a sentence. There will be only one ( and ) in the whole
> sentence. The sentence looks like:
>
> sadsajkdfskjdfs(kj454sd)errttyyu.

($stuff) = $sentence =~ /\((.*)\)/;

Read perldoc perlre or http://www.perldoc.com/perl5.6/pod/perlre.html

>
> Thanks!
>
>
>
>




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

Date: Wed, 21 Nov 2001 16:49:09 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: a simple question
Message-Id: <9tgidl$89a$03$1@news.t-online.com>

On Wed, 21 Nov 2001 10:37:26 -0500, Yong Zhang wrote:
> I am not familiar with perl. Can you tell me a easy way to get the stuff
> between ( and ) in a sentence. There will be only one ( and ) in the whole
> sentence. The sentence looks like:
> 
> sadsajkdfskjdfs(kj454sd)errttyyu.

my $a = "sadsajkdfskjdfs(kj454sd)errttyyu";
$a =~ /.*\((.*)\).*/;
print $1;
__END__
kj454sd

That means, your result is now in $1.

Tassilo
-- 
I think, therefore I am... I think.


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

Date: Wed, 21 Nov 2001 15:55:35 GMT
From: Ciaran McCreesh <keesh@users-dot-sf.net>
Subject: Re: a simple question
Message-Id: <X7QK7.13789$%j6.1390552@news1.cableinet.net>

Tassilo v. Parseval wrote:

> On Wed, 21 Nov 2001 10:37:26 -0500, Yong Zhang wrote:
>> I am not familiar with perl. Can you tell me a easy way to get the stuff
>> between ( and ) in a sentence. There will be only one ( and ) in the
>> whole sentence. The sentence looks like:
>> 
>> sadsajkdfskjdfs(kj454sd)errttyyu.
> 
> my $a = "sadsajkdfskjdfs(kj454sd)errttyyu";
> $a =~ /.*\((.*)\).*/;

I would have thought that the leading and trailing .* would be unnecessary 
and a performance hit. Since the regex isn't anchored, .* at the start 
simply forces the match to the end and gets it working backwards (since the 
OP said that there will only be one (), this does nothing). The .* at the 
end also just eats up CPU cycles, since who cares what's after the match?



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

Date: 21 Nov 2001 15:57:03 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: a simple question
Message-Id: <slrn9vnmlc.qsr.bernard.el-hagin@gdndev25.lido-tech>

On Wed, 21 Nov 2001 16:49:09 +0100, Tassilo v. Parseval
<Tassilo.Parseval@post.rwth-aachen.de> wrote:
> On Wed, 21 Nov 2001 10:37:26 -0500, Yong Zhang wrote:
>> I am not familiar with perl. Can you tell me a easy way to get the stuff
>> between ( and ) in a sentence. There will be only one ( and ) in the whole
>> sentence. The sentence looks like:
>> 
>> sadsajkdfskjdfs(kj454sd)errttyyu.
> 
> my $a = "sadsajkdfskjdfs(kj454sd)errttyyu";
> $a =~ /.*\((.*)\).*/;
         ^^        ^^

Totally unnecessary.


And you probably shouldn't encourage the use of $a in this
context, especially considering that this is a newbie asking.


Cheers,
Bernard


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

Date: 21 Nov 2001 06:42:42 -0800
From: merrill@missioncriticallinux.com (Hardy Merrill)
Subject: Re: Anyone Read  "Programming the Perl DBI" lately?
Message-Id: <fdfedf4b.0111210642.24ae8228@posting.google.com>

"Daniel Berger" <djberg96@hotmail.com> wrote in message news:<UoHK7.26$fN3.38286@typhoon.mn.mediaone.net>...
> "Jeff Zucker" <jeff@vpservices.com> wrote in message
> news:3BF9AFB3.CAB09DD5@vpservices.com...
> > Alicia Hirsch wrote:
> > >
> > > kindly show me how DBI support multiple tables in a
> > > single SQL statement
> > > ...
> > > I created 3 flat-file databases
> >
> > You can't currently do joins (which is what that is called) with
> > flat-files.  In about two weeks you will be able to when I release the
> > new SQL::Statement module that supports joins with flat files.  If you
> > can't wait until then, email me and I'll send you an advance copy.
> >
> > --
> > Jeff
> 
> That's interesting.  Thanks Jeff.  Hopefully Tim and O'Reilly are
> considering a 2nd edition for the book sometime next year with the changes
> he's made since 1.14 and some of the modules that have come out since.
> 
> Regards,
> 
> Dan

Jeff already took care of the flat-file issue.  If, on the other hand,
you want to try these examples using a real relational database, you
could install either MySQL(www.mysql.com) or
PostgreSQL(www.postgresql.org).  Assuming, just to pick one, that you
choose MySQL, you would
  1. install MySQL, and make sure that it's working properly
  2. install DBI (don't need to reinstall if it's already installed)
  3. install DBD::mysql - this is the database driver for MySQL
  4. create some tables and try your query examples from the book

HTH.
--
Hardy Merrill
Mission Critical Linux, Inc.
http://www.missioncriticallinux.com


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

Date: Wed, 21 Nov 2001 15:24:12 +0000
From: "Miguel Manso" <mmanso@yahoo.com>
Subject: Bitwise Operators - How to use?
Message-Id: <pan.2001.11.21.15.24.12.136.2766@yahoo.com>

Hi there.

I was reading the perlop man page an I saw the Bitwise operators
section... I've read it but I can't figure how the REAL use for them.

Can someone point me some clues?

Thanks.


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

Date: 21 Nov 2001 07:44:38 -0800
From: bh_ent@hotmail.com (Drew Myers)
Subject: Re: Can I avoid 2 passes?
Message-Id: <d1b6a249.0111210744.1f1e403@posting.google.com>

> Uri Guttman wrote:
> > Godzilla! wrote:
> > > Uri Guttman wrote:
> > > > Dale Henderson wrote:
> > > > > Drew Myers wrote:

Well, regardless of the "battle" that is or is not being waged, here
are the benchmark results I come up with:

Benchmark: timing 100 iterations of map, split, substr...
       map:  1 wallclock secs ( 0.21 usr +  0.01 sys =  0.22 CPU) @
454.55/s (n=100)
            (warning: too few iterations for a reliable count)
     split:  0 wallclock secs ( 0.30 usr +  0.01 sys =  0.31 CPU) @
322.58/s (n=100)
            (warning: too few iterations for a reliable count)
    substr:  0 wallclock secs ( 0.22 usr +  0.01 sys =  0.23 CPU) @
434.78/s (n=100)
            (warning: too few iterations for a reliable count)
Benchmark: timing 1000 iterations of map, split, substr...
       map:  2 wallclock secs ( 2.14 usr +  0.09 sys =  2.23 CPU) @
448.43/s (n=1000)
     split:  4 wallclock secs ( 3.05 usr +  0.09 sys =  3.14 CPU) @
318.47/s (n=1000)
    substr:  2 wallclock secs ( 2.19 usr +  0.08 sys =  2.27 CPU) @
440.53/s (n=1000)
Benchmark: timing 10000 iterations of map, split, substr...
       map: 22 wallclock secs (21.35 usr +  0.84 sys = 22.19 CPU) @
450.65/s (n=10000)
     split: 32 wallclock secs (30.29 usr +  0.85 sys = 31.14 CPU) @
321.13/s (n=10000)
    substr: 23 wallclock secs (21.83 usr +  0.86 sys = 22.69 CPU) @
440.72/s (n=10000)

So, map wins in all 3 instances I tested (100,1000,10000 iterations). 
Next is Godzilla's substr, and finally, what I think of as a
"traditional" split.

Thanks to everyone for your help! 

I've learned a lot,
Drew


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

Date: Wed, 21 Nov 2001 10:49:12 -0500
From: Lou Moran <ellem@techie.net>
Subject: Re: Can I avoid 2 passes?
Message-Id: <j3jnvtkh2l6q73c8morbuhg130qqnvh7ud@4ax.com>

On Tue, 20 Nov 2001 14:26:02 -0800, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote wonderful things about sparkplugs:

>Dale Henderson wrote:
> 
>> > Godzilla wrote:
snip
> 
>>      So what's the difference between a hash and and associative array?
>
> 
>Format, creation and access methodologies along with efficiency.
>
>An array is most often superior for all criteria.
>
>My suggestion is you research and read about arrays and hashes.
>It is clear you have a bit of Perl learning yet to accomplish;
>differences between arrays and hashes, are readily apparent.


Even _I_ know that a hash and an associative array are terms for the
same thing!

Pick better fights you'll come off looking smarter.  This is like a
newbie troll.  You're better than that.







--
ellem@techie.com


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

Date: Wed, 21 Nov 2001 08:05:12 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Can I avoid 2 passes?
Message-Id: <3BFBD0B8.BC04D88C@stomp.stomp.tokyo>

Drew Myers wrote:
 
> > Uri Guttman wrote:
> > > Godzilla! wrote:
> > > > Uri Guttman wrote:
> > > > > Dale Henderson wrote:
> > > > > > Drew Myers wrote:
 
> Well, regardless of the "battle" that is or is not being waged, here
> are the benchmark results I come up with:


Here are some benchmark results which have not been
falsely fabricated. As you know, map methods become
less efficient with larger data samples, Frank.


Godzilla!
--

#!perl

print "Content-type: text/plain\n\n";

use Benchmark;

print "Run One:\n\n";
&Time;

print "\n\nRun Two:\n\n";
&Time;

print "\n\nRun Three:\n\n";
&Time;


sub Time
 {
  timethese (1000000,
  {
   'name1' =>
   '%users = map split (/:/, $_, 2), <DATA> ;',

   'name2' =>
   'while (<DATA>)
    { $Users{substr ($_, 0, index ($_, ":"))} = substr ($_, index ($_, ":") + 1); }',
  } );
 }

__DATA__
user1:pass1:uid1:gid1:gecos1:home1:shell1
user2:pass2:uid2:gid2:gecos2:home2:shell2


PRINTED RESULTS:
________________

Run One:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 26 wallclock secs (27.51 usr +  0.00 sys = 27.51 CPU) @ 36350.42/s
 name2: 26 wallclock secs (25.82 usr +  0.00 sys = 25.82 CPU) @ 38729.67/s


Run Two:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 28 wallclock secs (27.58 usr +  0.00 sys = 27.58 CPU) @ 36258.16/s
 name2: 26 wallclock secs (26.04 usr +  0.00 sys = 26.04 CPU) @ 38402.46/s


Run Three:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 28 wallclock secs (27.79 usr +  0.00 sys = 27.79 CPU) @ 35984.17/s
 name2: 26 wallclock secs (25.64 usr +  0.00 sys = 25.64 CPU) @ 39001.56/s


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

Date: Wed, 21 Nov 2001 07:24:04 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Do Not Redirect CGI Questions To CIWAC
Message-Id: <3BFBC714.CAD65B62@stomp.stomp.tokyo>

Martien Verbruggen wrote:

>  Godzilla! wrote:

> > I will state again what I have recently stated.
> > Do not redirect people with cgi questions to
> > the comp.infosystems.www.authoring.cgi group.
 
> [Do not pay any attention to what Godzilla says. It is a  troll, and has
> no decent working knowledge of Perl or programming  in general. Search
> groups.google.com to see a history of its posts  and replies to these
> posts.]
 
> Do not get drawn into discussions with the troll.
 
> CGI questions are offtopic here. The best place to redirect them is
> comp.infosystems.www.authoring.cgi.


Which reminds me, over in CIWAC, should I continue referring
to you as Sheila King, or should I call you Martien? If you
like I will refer to you using your real name, Frank.


Godzilla!


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

Date: Wed, 21 Nov 2001 15:40:39 GMT
From: strien@inl.nl (Rob van Strien)
Subject: File position of of every word in a file
Message-Id: <3bfbc878.30012875@news.leidenuniv.nl>

Hi,

How can I get the file position of each single word in a file?
I can read the file line by line and chop it up in words, but
the tell-function will always return the file position of the
(end of the) line I'm on, not the words.

Thanks,
Rob van Strien
strien@inl.nl


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

Date: Wed, 21 Nov 2001 15:10:44 GMT
From: John Smith <nospam@newsranger.com>
Subject: Re: How to split variable length row
Message-Id: <UtPK7.32928$xS6.56092@www.newsranger.com>

Thank you guys for the solution.
I have to learn a lot.




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

Date: Wed, 21 Nov 2001 08:02:57 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: installing DBD::mysql on linux
Message-Id: <slrn9vnd4r.tjq.trammell@haqq.el-swifto.com>

On Wed, 21 Nov 2001 17:48:07 +0700, Antonius Herry Sukardi wrote:
> Currently I am trying to get perl (ver. 5.00503) working with MySQL
> (ver. 3.23.43) on a linux (RH 6.2) server.  I have installed both the
> server and client part of mysql and even created a database there.  Then
> I installed the perl modules that came with the RH 6.2.  I tested the
> perl by running simple scripts and seems to be working normally.  Now I
> try to make perl script which is able to talk to mysql.  I ran the CPAN
> commands: perl -MCPAN -e 'install DBI'.  It ran to completion and I
> didn't see any error messages. Then I ran the perl -MCPAN -e 'install
> DBD::mysql' This was where the problem started.  After running awhile it
> said that:
> can't exec "mysql_config": No such file or directory at Makefile.PL line
> 168
> Failed to determine directory of mysql.h
> 
> I search the entire server for mysql_config or mysql.h files, but it
> doesn't seem to exist in my computer.  Did I install the MySQL wrongly,
> or am I missing something ?
> I am not sure where the problem lies.  Is it on the perl or is it on the
> MySQL side.  Can anybody please help, or point me to the right direction
> ?

What happens when you go to www.google.com and search for the
phrase "Failed to determine directory of mysql.h"?



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

Date: Wed, 21 Nov 2001 09:32:13 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: IO::Select and IO::Socket question: multiple connections
Message-Id: <HVOK7.30779$bA4.1222438@wagner.videotron.net>


"Zoltan Kandi" <zoltan.kandi@tellabs.com> wrote in message
news:3BFBB8A2.92FAD800@tellabs.com...
> Dear All,
>
> I am developing an application, which listens to the incoming messages
> from several (up to 20) Windows NT servers running a proprietary NMS
> over a TCP-IP connection.
>
> This is the "listening" application:
>
> > use strict;
> > use IO::Socket;
> > use IO::Select;
> >
> > my $new_client = new IO::Socket::INET (
> >                                        LocalHost => '192.168.13.167',
> >                                        LocalPort => '7071',
> >                                        Proto => 'tcp',
> >                                        Listen => 16,
> >                                        Reuse => 1,
> >                                       );
> >
> > my ($read_handle,$read_set,@read_handle_set,$new_socket,$buf);
> >
> > $read_set = new IO::Select();
> > $read_set->add($new_client);
> >
> > while (@read_handle_set = $read_set->can_read)
> > {
> >
> >    foreach $read_handle (@read_handle_set)
> >    {
> >       if ($read_handle == $new_client)
> >       {
> >          $new_socket = $read_handle->accept();
> >          $read_set->add($new_socket);
> >       }
> >       else
> >       {
> >          $buf = <$read_handle>;
> >          if ($buf)
> >          {
> >             print $buf;
> >          }
> >          else
> >          {
> >             $read_set->remove($read_handle);
> >             close($read_handle);
> >          }
> >       }
> >    }
> > }
> > 1;
> >
>
> and this is the test script I run on several PCs to test the first one:
>
> > #!/etc/bin/perl -w
> > use strict;
> > use IO::Socket;
> > my $sock = new IO::Socket::INET ( PeerAddr => '192.168.13.167', PeerPort
=> '7071', Proto => 'tcp');
> > die "Could not create socket: $!\n" unless $sock;
> > print $sock 'hello there!\n';
> > close($sock);
> > 1;
>
> Maybe the script are not optimal, but this works perfectly.
> What I do miss is to be able to identify which client has sent which
> message. So what I want to do is as a new socket is created, it should
> be assigned some ID - I'm not sure a file or IO handle can be used as a
> hash key! What solution could you recommend?

Probably the best way is to have each client, after establishing the
connection, send a command that identifies itself. I don't know of your
proprietary protocol but something like "LOGIN: myname\n" or "IAM\x00myname"
should do the trick.

If that's impossible then my second suggestion is, if they have static IP
addresses, use that as the identifier. You can get the IP address by using
the peeraddr() method of a Socket object and run that through inet_ntoa().
What you can do then is use a static hash defined earlier in your program to
map IP ADDRESS => Username

I hope that helps.

>
> Thanks in advance and best regards,
>
>
> Zoltan Kandi, M. Sc.
> Product & Application Specialist
>
> Tellabs Netherlands BV
> Perkinsbaan 17
> 3439 ND Nieuwegein
>
> Tel:      +31 30 600 40 75
> Fax:      +31 30 600 40 90
> GSM:      +31 651 194 291
> Email:    Zoltan.Kandi@tellabs.com
> Internet: http://www.tellabs.com




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

Date: Wed, 21 Nov 2001 07:08:37 -0800
From: Derek Balling <dredd@megacity.org>
Subject: Re: IO::Select and IO::Socket question: multiple connections
Message-Id: <211120010708379710%dredd@megacity.org>

Perhaps I'm confused... what's wrong with:

    my $sockaddr = $read_handle->peername;
    my ($ip_addr) = (sockaddr_in($sockaddr))[1];
    my $connecting_host = gethostbyaddr($ip_addr,AF_INET);

Did I miss something as to why this isn't viable? This is what I do
now... :-/

D


In article <HVOK7.30779$bA4.1222438@wagner.videotron.net>, Mina Naguib
<spam@thecouch.homeip.net> wrote:

> "Zoltan Kandi" <zoltan.kandi@tellabs.com> wrote in message
> news:3BFBB8A2.92FAD800@tellabs.com...
> > Dear All,
> >
> > I am developing an application, which listens to the incoming messages
> > from several (up to 20) Windows NT servers running a proprietary NMS
> > over a TCP-IP connection.
> >
> > This is the "listening" application:
> >
> > > use strict;
> > > use IO::Socket;
> > > use IO::Select;
> > >
> > > my $new_client = new IO::Socket::INET (
> > >                                        LocalHost => '192.168.13.167',
> > >                                        LocalPort => '7071',
> > >                                        Proto => 'tcp',
> > >                                        Listen => 16,
> > >                                        Reuse => 1,
> > >                                       );
> > >
> > > my ($read_handle,$read_set,@read_handle_set,$new_socket,$buf);
> > >
> > > $read_set = new IO::Select();
> > > $read_set->add($new_client);
> > >
> > > while (@read_handle_set = $read_set->can_read)
> > > {
> > >
> > >    foreach $read_handle (@read_handle_set)
> > >    {
> > >       if ($read_handle == $new_client)
> > >       {
> > >          $new_socket = $read_handle->accept();
> > >          $read_set->add($new_socket);
> > >       }
> > >       else
> > >       {
> > >          $buf = <$read_handle>;
> > >          if ($buf)
> > >          {
> > >             print $buf;
> > >          }
> > >          else
> > >          {
> > >             $read_set->remove($read_handle);
> > >             close($read_handle);
> > >          }
> > >       }
> > >    }
> > > }
> > > 1;
> > >
> >
> > and this is the test script I run on several PCs to test the first one:
> >
> > > #!/etc/bin/perl -w
> > > use strict;
> > > use IO::Socket;
> > > my $sock = new IO::Socket::INET ( PeerAddr => '192.168.13.167', PeerPort
> => '7071', Proto => 'tcp');
> > > die "Could not create socket: $!\n" unless $sock;
> > > print $sock 'hello there!\n';
> > > close($sock);
> > > 1;
> >
> > Maybe the script are not optimal, but this works perfectly.
> > What I do miss is to be able to identify which client has sent which
> > message. So what I want to do is as a new socket is created, it should
> > be assigned some ID - I'm not sure a file or IO handle can be used as a
> > hash key! What solution could you recommend?
> 
> Probably the best way is to have each client, after establishing the
> connection, send a command that identifies itself. I don't know of your
> proprietary protocol but something like "LOGIN: myname\n" or "IAM\x00myname"
> should do the trick.
> 
> If that's impossible then my second suggestion is, if they have static IP
> addresses, use that as the identifier. You can get the IP address by using
> the peeraddr() method of a Socket object and run that through inet_ntoa().
> What you can do then is use a static hash defined earlier in your program to
> map IP ADDRESS => Username
> 
> I hope that helps.
> 
> >
> > Thanks in advance and best regards,
> >
> >
> > Zoltan Kandi, M. Sc.
> > Product & Application Specialist
> >
> > Tellabs Netherlands BV
> > Perkinsbaan 17
> > 3439 ND Nieuwegein
> >
> > Tel:      +31 30 600 40 75
> > Fax:      +31 30 600 40 90
> > GSM:      +31 651 194 291
> > Email:    Zoltan.Kandi@tellabs.com
> > Internet: http://www.tellabs.com


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

Date: Wed, 21 Nov 2001 10:15:29 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: IO::Select and IO::Socket question: multiple connections
Message-Id: <hyPK7.31394$bA4.1242693@wagner.videotron.net>


"Derek Balling" <dredd@megacity.org> wrote in message
news:211120010708379710%dredd@megacity.org...
> Perhaps I'm confused... what's wrong with:
>
>     my $sockaddr = $read_handle->peername;
>     my ($ip_addr) = (sockaddr_in($sockaddr))[1];
>     my $connecting_host = gethostbyaddr($ip_addr,AF_INET);
>
> Did I miss something as to why this isn't viable? This is what I do
> now... :-/

It's viable when all you want is the IP Address/Hostname of the other end of
the socket. However if you want further information, such as the name of the
person on the other end, or their username they logged into the application
with, or info from their pc, it'll have to be incorporated inside the
transaction inside your proprietary protocol.

>
> D
>
>
> In article <HVOK7.30779$bA4.1222438@wagner.videotron.net>, Mina Naguib
> <spam@thecouch.homeip.net> wrote:
>
> > "Zoltan Kandi" <zoltan.kandi@tellabs.com> wrote in message
> > news:3BFBB8A2.92FAD800@tellabs.com...
> > > Dear All,
> > >
> > > I am developing an application, which listens to the incoming messages
> > > from several (up to 20) Windows NT servers running a proprietary NMS
> > > over a TCP-IP connection.
> > >
> > > This is the "listening" application:
> > >
> > > > use strict;
> > > > use IO::Socket;
> > > > use IO::Select;
> > > >
> > > > my $new_client = new IO::Socket::INET (
> > > >                                        LocalHost =>
'192.168.13.167',
> > > >                                        LocalPort => '7071',
> > > >                                        Proto => 'tcp',
> > > >                                        Listen => 16,
> > > >                                        Reuse => 1,
> > > >                                       );
> > > >
> > > > my ($read_handle,$read_set,@read_handle_set,$new_socket,$buf);
> > > >
> > > > $read_set = new IO::Select();
> > > > $read_set->add($new_client);
> > > >
> > > > while (@read_handle_set = $read_set->can_read)
> > > > {
> > > >
> > > >    foreach $read_handle (@read_handle_set)
> > > >    {
> > > >       if ($read_handle == $new_client)
> > > >       {
> > > >          $new_socket = $read_handle->accept();
> > > >          $read_set->add($new_socket);
> > > >       }
> > > >       else
> > > >       {
> > > >          $buf = <$read_handle>;
> > > >          if ($buf)
> > > >          {
> > > >             print $buf;
> > > >          }
> > > >          else
> > > >          {
> > > >             $read_set->remove($read_handle);
> > > >             close($read_handle);
> > > >          }
> > > >       }
> > > >    }
> > > > }
> > > > 1;
> > > >
> > >
> > > and this is the test script I run on several PCs to test the first
one:
> > >
> > > > #!/etc/bin/perl -w
> > > > use strict;
> > > > use IO::Socket;
> > > > my $sock = new IO::Socket::INET ( PeerAddr => '192.168.13.167',
PeerPort
> > => '7071', Proto => 'tcp');
> > > > die "Could not create socket: $!\n" unless $sock;
> > > > print $sock 'hello there!\n';
> > > > close($sock);
> > > > 1;
> > >
> > > Maybe the script are not optimal, but this works perfectly.
> > > What I do miss is to be able to identify which client has sent which
> > > message. So what I want to do is as a new socket is created, it should
> > > be assigned some ID - I'm not sure a file or IO handle can be used as
a
> > > hash key! What solution could you recommend?
> >
> > Probably the best way is to have each client, after establishing the
> > connection, send a command that identifies itself. I don't know of your
> > proprietary protocol but something like "LOGIN: myname\n" or
"IAM\x00myname"
> > should do the trick.
> >
> > If that's impossible then my second suggestion is, if they have static
IP
> > addresses, use that as the identifier. You can get the IP address by
using
> > the peeraddr() method of a Socket object and run that through
inet_ntoa().
> > What you can do then is use a static hash defined earlier in your
program to
> > map IP ADDRESS => Username
> >
> > I hope that helps.
> >
> > >
> > > Thanks in advance and best regards,
> > >
> > >
> > > Zoltan Kandi, M. Sc.
> > > Product & Application Specialist
> > >
> > > Tellabs Netherlands BV
> > > Perkinsbaan 17
> > > 3439 ND Nieuwegein
> > >
> > > Tel:      +31 30 600 40 75
> > > Fax:      +31 30 600 40 90
> > > GSM:      +31 651 194 291
> > > Email:    Zoltan.Kandi@tellabs.com
> > > Internet: http://www.tellabs.com




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

Date: Wed, 21 Nov 2001 15:46:15 GMT
From: Zoltan Kandi <zoltan.kandi@tellabs.com>
Subject: Re: IO::Select and IO::Socket question: multiple connections
Message-Id: <3BFBD95B.790E99D9@tellabs.com>

Hi,

Mina Naguib wrote:
> 
> "Derek Balling" <dredd@megacity.org> wrote in message
> news:211120010708379710%dredd@megacity.org...
> > Perhaps I'm confused... what's wrong with:
> >
> >     my $sockaddr = $read_handle->peername;
> >     my ($ip_addr) = (sockaddr_in($sockaddr))[1];
> >     my $connecting_host = gethostbyaddr($ip_addr,AF_INET);
> >
> > Did I miss something as to why this isn't viable? This is what I do
> > now... :-/
> 
> It's viable when all you want is the IP Address/Hostname of the other end of
> the socket. However if you want further information, such as the name of the
> person on the other end, or their username they logged into the application
> with, or info from their pc, it'll have to be incorporated inside the
> transaction inside your proprietary protocol.
> 

Thanks for your comments so far.
The code Derek described is more than enough to identify the sender of
the data.
What's still missing is the following:


Since the NMS application on all 20 NT machines is running as a service,
it's not capable of setting up the necessary TCP/IP connection towards
my application, on the contrary, my app will have first to set up a
telnet
connection towards the NMS, log in, and only after a successful login
will be able to accept incoming packages. How do I set up this type
of connection?

TIA and best regards,

Zoltan Kandi, M. Sc.
Product & Application Specialist

Tellabs Netherlands BV
Perkinsbaan 17
3439 ND Nieuwegein

Tel:      +31 30 600 40 75
Fax:      +31 30 600 40 90
GSM:      +31 651 194 291
Email:    Zoltan.Kandi@tellabs.com
Internet: http://www.tellabs.com


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

Date: Wed, 21 Nov 2001 14:09:35 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: LWP::UserAgent Post & Session problem
Message-Id: <slrn9vnaa2.nm2.tadmc@tadmc26.august.net>

derek chen <u8526505@ms27.hinet.net> wrote:

>I used post method to request a page and got a redirect address which
        ^^^^                                    ^^^^^^^^

>What can I do to solve this problem
>just like a browser does.


Search for "redirect" in the documentation for the module that
you are using  :-)


----------------------------------
=item $ua->redirect_ok

This method is called by request() before it tries to do any
redirects.  It should return a true value if a redirect is allowed
to be performed. Subclasses might want to override this.

The default implementation will return FALSE for POST request and TRUE
for all others.
----------------------------------

So you need to override redirect_ok() so that it will return
true for POST requests. Randal has some code for overriding it
in one of his Web Techniques columns:

   http://www.stonehenge.com/merlyn/WebTechniques/col11.listing.txt

But you want redirect_ok() to return one rather than zero.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

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.  

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


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