[32563] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3829 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 1 09:10:43 2012

Date: Sat, 1 Dec 2012 06:09:07 -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           Sat, 1 Dec 2012     Volume: 11 Number: 3829

Today's topics:
        Clickable link conversion regex? <tuxedo@mailinator.com>
        perl chat server <majid.complex@gmail.com>
    Re: perl chat server <jurgenex@hotmail.com>
    Re: perl chat server <majid.complex@gmail.com>
    Re: perl chat server <jimsgibson@gmail.com>
    Re: perl chat server <majid.complex@gmail.com>
    Re: perl chat server <jurgenex@hotmail.com>
    Re: perl chat server <majid.complex@gmail.com>
    Re: perl chat server <jimsgibson@gmail.com>
    Re: perl chat server <majid.complex@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 30 Nov 2012 22:51:33 +0100
From: Tuxedo <tuxedo@mailinator.com>
Subject: Clickable link conversion regex?
Message-Id: <k9b9p6$a59$1@news.albasani.net>

Can anyone suggest a solution to enclose bare urls with href tags?

open(my $fh, 'urls.txt') or die $!;

while (my $line = <$fh>) {
$line =~ s[...]    # match http or https instances
            [...]s;  # replace with enclosing hrefs
print $line;
}

The input format may be one or more URLs p/line.

Each scheme begins with either http:// or https:// but not necessarily as a 
first string on a line.

Each URL ends with either the end of a line or a whitespace.

The input file would look like for example:

---------- urls.txt -------

http://www.example.com/hello
 http://www.example.com/

bla https://www.example.com/a_page.htm plus a string not part of the URL

-----------

If an http or https string already has a preceding occurrence of a closing 
html tag ">", such as:
<a href=http://bla.com>http://bla.com</a>
 ... then it should be excluded with no replacement.

Two conditions exist in the input file:

The 'http' or 'https' bit will always begin at the first character on a new 
line or have a preceding whitespace immediately before itself, like:

 http://someurl.com line w/ whitespace before
http://someother.com
hello http://bla.com also w/ a whitespace before

The match and replace output on the above three lines would then be:

 <a href=http://someurl.com>http://someurl.com</a> line w/ whitespace before
<a href=http://someother.com>http://someother.com</a>
hello <a href=http://bla.com>http://bla.com</a> also w/ a whitespace before

In case something may written as http://bla, which as in this sentence 
isn't a link, it would inadvertently end up being converted into a link, 
but that would be a rare occurrence. In other words, without additional 
validity checking, the regex would be a best-guess procedure. For a more 
strict procedure, each match could perhaps be checked against a 
is_web_uri($...) function using Data::Validate::URI that validates http or 
https URIs specifically. That said, any example that illustrates a basic 
search and replace concept be much appreciated, even if it's only a 
best-guess URL type of procedure.

Many thanks for any bright ideas!

Tuxedo


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

Date: Fri, 30 Nov 2012 11:16:55 -0800 (PST)
From: Majid Dehghan <majid.complex@gmail.com>
Subject: perl chat server
Message-Id: <63546c91-2ee5-4960-9bd7-2e665568f360@googlegroups.com>

hey everyone,
i'm new to Perl,i'm curios to know how to send a message to a specific user, EX:from user A to user B,not to everyone,
thanks in advance.


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

Date: Fri, 30 Nov 2012 11:35:03 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: perl chat server
Message-Id: <4c2ib8pfipp0e7sekbrrmoqa918i98v26h@4ax.com>

Majid Dehghan <majid.complex@gmail.com> wrote:
>i'm new to Perl,i'm curios to know how to send a message to a specific user, EX:from user A to user B,not to everyone,

Usually you use email. On CPAN (cpan.org) you will find numerous modules
that help dealing with any aspect related to email.

jue


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

Date: Fri, 30 Nov 2012 11:48:25 -0800 (PST)
From: Majid Dehghan <majid.complex@gmail.com>
Subject: Re: perl chat server
Message-Id: <f644f7de-7d20-4b2f-a6cb-e613a17b6e5f@googlegroups.com>

thanks for the reply,
but this is a simple chat server,i mentioned it in subject,
after accepting clients,i want to be able to send a message from one user to another one,just the two of them (something like private message)
like keeping all the connected socket in an array,but i just don't know how to!
thanks


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

Date: Fri, 30 Nov 2012 13:00:45 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: perl chat server
Message-Id: <301120121300459774%jimsgibson@gmail.com>

In article <63546c91-2ee5-4960-9bd7-2e665568f360@googlegroups.com>,
Majid Dehghan <majid.complex@gmail.com> wrote:

> hey everyone,
> i'm new to Perl,i'm curios to know how to send a message to a specific user,
> EX:from user A to user B,not to everyone,
> thanks in advance.

I googled for 'perl chat server' and came up with several
interesting-looking links, including this one:

<http://poe.perl.org/?POE_Cookbook/Chat_Server>

-- 
Jim Gibson


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

Date: Fri, 30 Nov 2012 13:09:41 -0800 (PST)
From: Majid Dehghan <majid.complex@gmail.com>
Subject: Re: perl chat server
Message-Id: <ce6b7a31-b156-4ec6-a33a-2a39b17ee055@googlegroups.com>

much appreciated Jim Gibson,
but you see ("# Handle a connection.  Register the new user, and broadcast a message # to whoever is already connected.")
i don't want that,i just want to send a message from one user to only another one,not all connected client.
i googled it too,but i need someone to guide me

thanks



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

Date: Fri, 30 Nov 2012 13:28:13 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: perl chat server
Message-Id: <su8ib8llpb2iqjqrq1g18lefphfk2f2dd3@4ax.com>

Majid Dehghan <majid.complex@gmail.com> wrote:
>thanks for the reply,
>but this is a simple chat server,i mentioned it in subject,
>after accepting clients,i want to be able to send a message from one user to another one,just the two of them (something like private message)
>like keeping all the connected socket in an array,but i just don't know how to!
>thanks

Honestly, what on earth are you talking about? Do you want to write an
Instant Messaging System (IM) from scratch? Do you want to connect to an
existing IM server using a Perl client? Do you have a multi-user chat
system up and running (WHICH ONE?) and want to enhance its
functionality? What do you want?

Sockets and arrays are implementation details which are waaaaaaaay to
detailed at this time.

jue


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

Date: Fri, 30 Nov 2012 13:41:26 -0800 (PST)
From: Majid Dehghan <majid.complex@gmail.com>
Subject: Re: perl chat server
Message-Id: <b71a6432-7e49-4cbb-9aef-8d0acede8870@googlegroups.com>

Consider a chat server,clients connect to this server and chat to each other,this is my code so far:
use strict;
use IO::Socket;
use IO::Select;
my $srv=IO::Socket::INET->new(LocalPort=>'5000',Proto=>'tcp',Reuse=>1,Listen=>5) or die 'SOCKET';
print "SEVER READY\nWaiting For Connection\n";
my $sel=IO::Select->new;
$sel->add($srv);

while(my @inp=$sel->can_read()) {
foreach my $c (@inp) {

if($c eq $srv) {
my $clnt=$srv->accept();
my $host=$clnt->peerhost();
my $port=$clnt->peerport();
my $c=$sel->count;
print $clnt "--- $c users(s) online ---\nPress q for exit\n";
$sel->add($clnt);
print "Got Connection from \"$host\" at port $port\n";
}
else {
my $msgin=<$c>;
chop($msgin);
chop($msgin);
if($msgin eq "q") { 
$sel->remove($c);
$c->close; }

else {
foreach($sel->can_write()) {
print $_ $msgin;}}
}
}}
but whenever any client try to send a message it'll be broadcast,consider i want to get a message from the client#2 and send it to client#3 what should i do?
i hope i make myself clear.


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

Date: Fri, 30 Nov 2012 14:26:54 -0800
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: perl chat server
Message-Id: <301120121426544597%jimsgibson@gmail.com>

In article <ce6b7a31-b156-4ec6-a33a-2a39b17ee055@googlegroups.com>,
Majid Dehghan <majid.complex@gmail.com> wrote:

> much appreciated Jim Gibson,
> but you see ("# Handle a connection.  Register the new user, and broadcast a
> message # to whoever is already connected.")
> i don't want that,i just want to send a message from one user to only another
> one,not all connected client.
> i googled it too,but i need someone to guide me

You need a way for clients to identify themselves to each other and to
the server. Then, the client needs to specify to which other client his
message will be sent. Then, instead of sending each incoming message to
all clients, you send it to only the client specified by the sender.

When a client connects, you should still probably send out a message to
all clients informing them that a new client has joined the service, is
ready to receive messages, and what their "handle" is. You will also
have to send the new client the list of existing clients.

-- 
Jim Gibson


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

Date: Fri, 30 Nov 2012 14:33:52 -0800 (PST)
From: Majid Dehghan <majid.complex@gmail.com>
Subject: Re: perl chat server
Message-Id: <fc76051a-6479-4dc4-936f-ffb72391211d@googlegroups.com>

thanks Jim
>You need a way for clients to identify themselves to each other and to 
the serve.

could you be more specific,
how to do that?


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

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


Administrivia:

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

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

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


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


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