[26018] in Perl-Users-Digest
Perl-Users Digest, Issue: 8234 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 8 16:21:51 2005
Date: Thu, 7 Jul 2005 15: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 Thu, 7 Jul 2005 Volume: 10 Number: 8234
Today's topics:
Getting associative array from a hash <ignoramus28164@NOSPAM.28164.invalid>
Re: Getting associative array from a hash <nobull@mail.com>
Re: Getting associative array from a hash <ignoramus28164@NOSPAM.28164.invalid>
Problem regarding socket <vikrantREMOVE@DELETEsaysnetsoftDDDD.com>
Re: Problem regarding socket <jgibson@mail.arc.nasa.gov>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 07 Jul 2005 19:10:11 GMT
From: Ignoramus28164 <ignoramus28164@NOSPAM.28164.invalid>
Subject: Getting associative array from a hash
Message-Id: <n6fze.1236$1_2.124@fe25.usenetserver.com>
I wrote a perl based algebra expression simplifier with work shown.
http://www.algebra.com/services/rendering/simplifier.mpl
It uses deeply nested structures of hashes holding references to
arrays.
Example:
my $term = { factors => [ $factor1, $factor2], operator => '+' };
I often need to get, say, the quantity of item in array held by the
hash.
I do it like this:
my $factors = $term->{factors};
print "Count = " . $#$factors . ".\n";
Unfortunately, this infolves creation of a temporary variable. Can I
avoid using a temporary?
Also, how can I access an element by number, instead of using
$$factors[0], can I say something like @($term->{factors})[0] or some
such, without using a temporary variable.
thanks
i
------------------------------
Date: Thu, 07 Jul 2005 20:45:29 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Getting associative array from a hash
Message-Id: <dak0oo$2n2$1@redhat2.bham.ac.uk>
Ignoramus28164 wrote:
> my $factors = $term->{factors};
>
> print "Count = " . $#$factors . ".\n";
>
> Unfortunately, this infolves creation of a temporary variable. Can I
> avoid using a temporary?
> print "Count = $#{$term->{factors}}.\n";
>
> Also, how can I access an element by number, instead of using
> $$factors[0], can I say something like @($term->{factors})[0] or some
> such, without using a temporary variable.
$term->{factors}[0]
OR
$term->{factors}->[0]
OR
${$term->{factors}}[0]
OR (if you want to access a slice)
@{$term->{factors}}[0]
Note: documentation on using references in Perl can be found in the
manual perlref.
------------------------------
Date: Thu, 07 Jul 2005 19:53:29 GMT
From: Ignoramus28164 <ignoramus28164@NOSPAM.28164.invalid>
Subject: Re: Getting associative array from a hash
Message-Id: <ZKfze.380$oH5.275@fe01.usenetserver.com>
Thanks Brian, that's awesome!
i
On Thu, 07 Jul 2005 20:45:29 +0100, Brian McCauley <nobull@mail.com> wrote:
> Ignoramus28164 wrote:
>
>> my $factors = $term->{factors};
>>
>> print "Count = " . $#$factors . ".\n";
>>
>> Unfortunately, this infolves creation of a temporary variable. Can I
>> avoid using a temporary?
>
> > print "Count = $#{$term->{factors}}.\n";
>
>>
>> Also, how can I access an element by number, instead of using
>> $$factors[0], can I say something like @($term->{factors})[0] or some
>> such, without using a temporary variable.
>
> $term->{factors}[0]
>
> OR
>
> $term->{factors}->[0]
>
> OR
>
> ${$term->{factors}}[0]
>
> OR (if you want to access a slice)
>
> @{$term->{factors}}[0]
>
> Note: documentation on using references in Perl can be found in the
> manual perlref.
>
--
------------------------------
Date: Thu, 07 Jul 2005 21:22:33 +0530
From: Vikrant <vikrantREMOVE@DELETEsaysnetsoftDDDD.com>
Subject: Problem regarding socket
Message-Id: <dajj6g$a87$1@domitilla.aioe.org>
hi
In the following code i am receving data from the client in a
buffer($sBuffer) and concatenating it into a another variable
$sData_Recevied.
My problem is that i can not understand what condition i should give in
do-while loop to exit if a certain time period elapses without any
data being received from the client. I have already tried the code
below, but it is not exiting the loop after 10 seconds.
########################################################################
#!/usr/bin/perl -w
use Socket;
$SOCKET_PORT =36545;
#Create
socket(hSERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
$iListener_Socket = sockaddr_in($SOCKET_PORT, INADDR_ANY);
#Binding
bind(hSERVER,$iListener_Socket)
or die "Couldn't connect to Remote Host : $!\n";
#Listen
listen(hSERVER,4);
accept(hCLIENT,hSERVER);
$iEndTime = time() + 10;
do
{
recv(hCLIENT,$sBuffer,1024,0); #Receving Data at Socket
$sData_Recevied.=$sBuffer;
}while($iEndTime > time());
$sReturnXML = "Data has been recevied";
send(hCLIENT,$sReturnXML,0);
close(hCLIENT);
close(hSERVER);
#################################################################################
Thanks
Vikrant
------------------------------
Date: Thu, 07 Jul 2005 13:30:49 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Problem regarding socket
Message-Id: <070720051330496431%jgibson@mail.arc.nasa.gov>
In article <dajj6g$a87$1@domitilla.aioe.org>, Vikrant
<vikrantREMOVE@DELETEsaysnetsoftDDDD.com> wrote:
> hi
>
> In the following code i am receving data from the client in a
> buffer($sBuffer) and concatenating it into a another variable
> $sData_Recevied.
>
> My problem is that i can not understand what condition i should give in
> do-while loop to exit if a certain time period elapses without any
> data being received from the client. I have already tried the code
> below, but it is not exiting the loop after 10 seconds.
As Paul pointed out, recv() is going to block until it gets some data,
so your program never gets to the time test. In addition to the
suggestion of using alarm(), you might want to investigate the select
(4 argument version) for waiting for I/O with a timeout. You should
also look into using the IO::Socket class, which has a timeout() method
for setting timeouts.
[socket program using Socket class snipped]
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
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 8234
***************************************