[29154] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 398 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 2 14:14:21 2007

Date: Wed, 2 May 2007 11:14:13 -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           Wed, 2 May 2007     Volume: 11 Number: 398

Today's topics:
    Re: Sockets <mgjv@tradingpost.com.au>
    Re: Sockets <dale.schmitz@offutt.af.mil>
    Re: Sockets xhoster@gmail.com
    Re: Sockets <jgibson@mail.arc.nasa.gov>
    Re: SQL statement in Perl doesn't work <zen13097@zen.co.uk>
        what is "}{"? <zennylenny@gmail.com>
    Re: what is "}{"? <nobull67@gmail.com>
    Re: what is "}{"? <spamtrap@dot-app.org>
    Re: what is "}{"? <klaus03@gmail.com>
    Re: what is "}{"? <attn.steven.kuo@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 2 May 2007 18:15:47 +1000
From: Martien verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Sockets
Message-Id: <slrnf3gi5j.bob.mgjv@martien.heliotrope.home>

On 1 May 2007 17:55:59 -0700,
	Monty <dale.schmitz@offutt.af.mil> wrote:
>> Actually, I just checked, and IO::Select
>> objects are indeed references to arrays, but again, it doesn't matter.
>
> Actually, to me, at this stage of understanding, it kind of does
> matter that it's an array.  While it could have been an array, a list,
> or a hash, those structures are at least familiar and I know means
> exist for traipsing through them.  So now the statement @ready = $sel-
>>can_read begins to shed light for me.

But that doesn't actually have anything to wo with what the IO::Select
object is. It simply has to do with what the can_read method in the
IO::Select package returns. It returns a list of file handles ready for
reading. That list is then stored in the array @ready.

>> One of the points of OO classes is to encapsulate and hide the
>> implementation from the user of the class. It should never be necessary
>> to need to know what exactly underlies the implementation.
>
> In practice, I won't need to refresh myself with the underlying
> mechanisms, but they are important to learn from.

Learning is good. But you do need to make sure that you're learning the
right things. Starting with the basics -- and someone else has already
suggested a list of documents to start with -- is important, before you
start to read OO module code, which can be, and often is, rather terse
and sometimes somewhat obscure.

> So this is what I've got from all this so far: IO::Select allows me to
> 'peruse', if you will, all the connections associated with a port I
> designate in a client-server connection, upon or through which I've
> established a communications socket (bear with me if this is rambling
> a bit).  Somewhere in the system, something is keeping track of all
> the connections I establish through that port, and IO::Select helps me
> look at them all.
>
> How's that so far?

Sort of ok-ish :)

IO::Select is one of the ways to package up a load of file handles, and
check them in bulk.

The file handles are most often connected to sockets, but don't have to
be. They are most often all of the same type, but they don't have to be. 

But in the most used configuration, IO::Select does what you describe.
So, by the way, does the perl builtin select. IO::Select just gives you
a much nicer and easy to use interface.

Martien
-- 
                        | 
Martien Verbruggen      | I took an IQ test and the results were
                        | negative.
                        | 


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

Date: 2 May 2007 05:38:20 -0700
From: Monty <dale.schmitz@offutt.af.mil>
Subject: Re: Sockets
Message-Id: <1178109500.272872.57380@q75g2000hsh.googlegroups.com>

Ok, so I'm not too far off on my thinking.  If you'd be so kind, I'd
like to 'talk out' the level of understanding I have about sockets,
ports, and maybe ask, later, about these file handles associated with
them.  Some how I'm a bit surprised that the can_read method of
IO::Select in regards to sockets involves file handles (not entirely
surprised; everything in UNIX is a file).  I expected something else,
but what else, I don't know.

With the coding of a new IO::Socket::INET I specify, among other
things, a port and a Listen parameter, which in this case is greater
than 1, meaning I can have more than one communication 'stream' that
is separate and distinct from others on that port.  The only education
I have along these lines is a brief explanation of FTP, where I'm told
communications between MyComputer and YourComputer are established via
a well-known port (21, I believe) and once the two systems agree to
talk, they also agree to further the conversation on a not-well-known
port, freeing up 21 for further FTP requests.

Is something similar going on with my socket?  That would clear up one
part of the mystery.

The second, these file handles, leads me to believe that somewhere on
the system I would expect to find a file designated as a socket (with
Solaris, that designation is noted by the '=' at the end of the file
name).  Is that the case?




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

Date: 02 May 2007 16:30:26 GMT
From: xhoster@gmail.com
Subject: Re: Sockets
Message-Id: <20070502123028.150$uW@newsreader.com>

Monty <dale.schmitz@offutt.af.mil> wrote:
>
> In practice, I won't need to refresh myself with the underlying
> mechanisms, but they are important to learn from.
>
> So this is what I've got from all this so far: IO::Select allows me to
> 'peruse', if you will, all the connections associated with a port I
> designate in a client-server connection,

IO::Select operates on the file handles that you stuff into it.  In this
case, such stuffing is done with both the "new" call and in the "add" call.

IO::Select does not know or care how you arrived at the file handles which
you stuff into it.  They could come from the same port, from different
ports, from named pipes or other special files, whatever.


> upon or through which I've
> established a communications socket (bear with me if this is rambling
> a bit).  Somewhere in the system, something is keeping track of all
> the connections I establish through that port,

The "somewhere" and "something" are in the statements:

$sel = new IO::Select( $lsn );

and then later in the

$sel->add($new);

So it isn't the system that is keeping track, it is you, through your
code, who is keeping track.


> and IO::Select helps me
> look at them all.

It helps you know which ones are immediately available for reading (or, in
the case of $lsn, available for accepting) without blocking.

Xho

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


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

Date: Wed, 02 May 2007 09:54:16 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Sockets
Message-Id: <020520070954162399%jgibson@mail.arc.nasa.gov>

In article <1178109500.272872.57380@q75g2000hsh.googlegroups.com>,
Monty <dale.schmitz@offutt.af.mil> wrote:

> Ok, so I'm not too far off on my thinking.  If you'd be so kind, I'd
> like to 'talk out' the level of understanding I have about sockets,
> ports, and maybe ask, later, about these file handles associated with
> them.  Some how I'm a bit surprised that the can_read method of
> IO::Select in regards to sockets involves file handles (not entirely
> surprised; everything in UNIX is a file).  I expected something else,
> but what else, I don't know.

A Perl newsgroup is not the most appropriate place to discuss network
programming. I suggest you get the book "UNIX Network Programming, Vol.
1", by Richard Stevens <http://safari.awprofessional.com/0131411551>

> 
> With the coding of a new IO::Socket::INET I specify, among other
> things, a port and a Listen parameter, which in this case is greater
> than 1, meaning I can have more than one communication 'stream' that
> is separate and distinct from others on that port.

No. The listen parameter is merely the number of connecting sockets
(remote connection attempts) that can be queued up during between the
time that the remote client does a "connect" and the local server does
an "accept". The default and usual maximum number is 5. It has nothing
to do with the number of sockets a process may have open at any one
time. That is a much larger number than 5, but depends upon your
installation.

> The only education
> I have along these lines is a brief explanation of FTP, where I'm told
> communications between MyComputer and YourComputer are established via
> a well-known port (21, I believe) and once the two systems agree to
> talk, they also agree to further the conversation on a not-well-known
> port, freeing up 21 for further FTP requests.
> 
> Is something similar going on with my socket?  That would clear up one
> part of the mystery.

The same thing happens on any server socket. The host listens for
connections on the server socket. When a client connects, a new,
temporary socket is created on each host.

> 
> The second, these file handles, leads me to believe that somewhere on
> the system I would expect to find a file designated as a socket (with
> Solaris, that designation is noted by the '=' at the end of the file
> name).  Is that the case?

No. Internet sockets are not part of the file system. On Unix-like
systems, you can display active sockets with the netstat utility.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: 02 May 2007 08:32:42 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: SQL statement in Perl doesn't work
Message-Id: <46384caa$0$21841$db0fefd9@news.zen.co.uk>

On 27 Apr 2007 00:41:47 -0700, ikeon <shay.rozen@gmail.com> wrote:
> > Huub wrote:
> >
> > > $betaald2006 = "select betaald2006 from hvw where lidnr = $record and
> > > naam != ' ' and kenmerk2006 is null";
> >
 
>  Maybe the problem is in the quote inside. maybe try:
> 
>  $betaald2006 = "select betaald2006 from hvw where lidnr = $record and
>  naam != \' \' and kenmerk2006 is null";

Or maybe not. Why do you think escaping the ' will make any
difference? Did you try it to see? You will find out that $betaald2006
contains exactly the same string, regardless.

' has no special meaning inside a double-quoted string, so there is no
need to escape it.



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

Date: 2 May 2007 10:39:58 -0700
From: zenny lenny <zennylenny@gmail.com>
Subject: what is "}{"?
Message-Id: <1178127598.567833.260790@y80g2000hsf.googlegroups.com>

I DID check the FAQ first.

Two questions:

1. This code adds a column of numbers:  perl -lne '$x+=$_}{print $x;'

What is the purpose of "}{"?

2. Is there any way to search groups or the web for symbols like "}
{"?  Google seems to ignore symbols like this.



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

Date: 2 May 2007 10:48:57 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: what is "}{"?
Message-Id: <1178128137.210077.148770@o5g2000hsb.googlegroups.com>

On May 2, 6:39 pm, zenny lenny <zennyle...@gmail.com> wrote:
> I DID check the FAQ first.
>
> Two questions:
>
> 1. This code adds a column of numbers:  perl -lne '$x+=$_}{print $x;'
>
> What is the purpose of "}{"?

It is the end of one block (executed once per line) and the start of
another block (executed once).

It makes sense if you know what -n actually does.

The above is simply short for:

perl -le ''LINE: while (<>) {$x+=$_}{print $x;}'

> 2. Is there any way to search groups or the web for symbols like "}
> {"?

Not that I know of.

However you could perhaps grep the Perl manual - this trick may be
mentioned in there somewhere.



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

Date: Wed, 02 May 2007 13:49:51 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: what is "}{"?
Message-Id: <m2fy6f15fk.fsf@local.wv-www.com>

zenny lenny <zennylenny@gmail.com> writes:

> I DID check the FAQ first.
>
> Two questions:
>
> 1. This code adds a column of numbers:  perl -lne '$x+=$_}{print $x;'
>
> What is the purpose of "}{"?

The -n switch tells Perl to include an implicit "input loop" around the
script you give it. This loop looks like:

    while (<>) {
        # ... your code here
    }

The "}{" in the above is just a clever way to insert something after the
end of the input loop. Formatted for clarity, it expands to this:

    while (<>) {
        # ... Your code begins here
        $x += $_
    }

    {
        print $x;
        # ... Your code ends here
    }

> 2. Is there any way to search groups or the web for symbols like "}
> {"?  Google seems to ignore symbols like this.

None that I know of.

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: 2 May 2007 11:01:09 -0700
From: Klaus <klaus03@gmail.com>
Subject: Re: what is "}{"?
Message-Id: <1178128869.357303.207970@y5g2000hsa.googlegroups.com>

On May 2, 7:39 pm, zenny lenny <zennyle...@gmail.com> wrote:
> 1. This code adds a column of numbers:  perl -lne '$x+=$_}{print $x;'
> What is the purpose of "}{"?

You are using "-n" in a very clever way indeed:

perldoc perlrun:
>> ====================
>> -n
>> causes Perl to assume the following loop around
>> your program, which makes it iterate over filename
>> arguments somewhat like sed -n or awk:
>>
>> LINE:
>> while (<>) {
>>     ... # your program goes here
>> }
>> ====================

 ...so with '$x+=$_}{print $x;'
your program will be...

LINE:
while (<>) {
    $x+=$_}{print $x;
}

 ...or reformatted...

LINE:
while (<>) {
    $x+=$_
}
{ print $x; }

--  Klaus



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

Date: 2 May 2007 11:05:52 -0700
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: what is "}{"?
Message-Id: <1178129152.457542.266120@n76g2000hsh.googlegroups.com>

On May 2, 10:39 am, zenny lenny <zennyle...@gmail.com> wrote:
> I DID check the FAQ first.
>
> Two questions:
>
> 1. This code adds a column of numbers:  perl -lne '$x+=$_}{print $x;'
>
> What is the purpose of "}{"?
>
> 2. Is there any way to search groups or the web for symbols like "}
> {"?  Google seems to ignore symbols like this.



Heh,  that's intentional obfuscation.  Abigail explains it
here (see the "Counting Lines" section):

    http://ucan.foad.org/~abigail/Perl/Talks/Japhs/

The -n switch (see 'perldoc perlrun') wraps your
code, similar to -p but without the continue and
print portion.

You can also use a module to make things clearer:

$ perl -MO=Deparse -nle '$x+=$_}{print $x;'

BEGIN { $/ = "\n"; $\ = "\n"; }
LINE: while (defined($_ = <ARGV>)) {
    chomp $_;
    $x += $_;
}
{
    print $x;
}
-e syntax OK


--
Hope this helps,
Steven



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

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


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