[28162] in Perl-Users-Digest
Perl-Users Digest, Issue: 9526 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 26 11:05:52 2006
Date: Wed, 26 Jul 2006 08:05:06 -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, 26 Jul 2006 Volume: 10 Number: 9526
Today's topics:
Re: anyone here tried higher order perl by dominus? I f <bik.mido@tiscalinet.it>
Re: anyone here tried higher order perl by dominus? I f <tzz@lifelogs.com>
Re: Comparing values of multiple hash keys <rvtol+news@isolution.nl>
Count values in multi dimensional array <oli.meister@gmail.com>
Re: Count values in multi dimensional array <1usa@llenroc.ude.invalid>
Re: Count values in multi dimensional array anno4000@radom.zrz.tu-berlin.de
Re: Count values in multi dimensional array <oli.meister@gmail.com>
Re: Count values in multi dimensional array anno4000@radom.zrz.tu-berlin.de
Re: counting number of uniques in a multidimensional ar <tadmc@augustmail.com>
Re: counting number of uniques in a multidimensional ar <tadmc@augustmail.com>
Re: counting number of uniques in a multidimensional ar <tadmc@augustmail.com>
Re: counting number of uniques in a multidimensional ar <tzz@lifelogs.com>
Re: dumb question about whether hashes get cleared from <zentara@highstream.net>
garbage collector <Michael.F123@gmail.com>
Re: garbage collector <bik.mido@tiscalinet.it>
Re: How to send utf-8 data using LWP::UserAgent? <g111@netcologne.de>
Re: How to send utf-8 data using LWP::UserAgent? <flavell@physics.gla.ac.uk>
Re: Questions about (non-blocking) sockets <spam.trap.never.read@mailinator.com>
Re: Regex query anno4000@radom.zrz.tu-berlin.de
Re: Regex query <simon.chao@fmr.com>
Re: Regex query anno4000@radom.zrz.tu-berlin.de
Re: Regex query <simon.chao@fmr.com>
Re: Regex query <tzz@lifelogs.com>
Re: using session managment in perl <noreply@gunnar.cc>
Re: using session managment in perl <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: using session managment in perl <tzz@lifelogs.com>
Re: using session managment in perl <benmorrow@tiscali.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Jul 2006 14:47:56 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: anyone here tried higher order perl by dominus? I found it free online and it seems very interesting
Message-Id: <f2pec2dfjfnmto9n7p9q6mini6mcfb9fou@4ax.com>
On 26 Jul 2006 04:49:47 GMT, John Bokma <john@castleamber.com> wrote:
>> or should I go straight to something supposedly powerful like lisp?
>> smalltalk or haskell?
[snip]
>In what way is Lisp/Smalltalk/Haskell more powerfull compared to Perl?
The correct question would be: in what way is Lisp/Smalltalk/Haskell
*sipposed to be* more powerfull compared to Perl?
Indeed I bet that even the most keen enthusiasts of any of the above
languages wouldn't make such a claim, although they would probably
point out some advantages or points of force of that particular
language over Perl (and anything else) in some particular area...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 26 Jul 2006 10:33:16 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: anyone here tried higher order perl by dominus? I found it free online and it seems very interesting
Message-Id: <g69bqrcl9lf.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 26 Jul 2006, bootiack@yahoo.com wrote:
> It says how perl is not limited to being a c clone.
> And I am wondering if perl is a good way for me to get into programming
You should start with a good background in algorithms, data
structures, and computers (hardware and OS), IMO. If you have that
background, you can learn with almost any language. Perl is good, but
it can be very confusing if you don't understand data and control
structures well (arrays, hashes, if/then, loop, subroutines).
HOP is much too advanced if you are just starting. I found it
fascinating, but far beyond the level of most intermediate
programmers.
> or should I go straight to something supposedly powerful like lisp?
> smalltalk or haskell?
None of those are better or worse than Perl, they are just different.
I could go into a lot of detail here on Perl vs. Java vs. Lisp vs. C
vs. C++, but what's the point? You're asking if you should learn to
drive with a BMW or an Audi or a Ferrari. The answer is that you
should learn about the driving laws and rules first, and ideally learn
with an instructor, before you "drive" on your own. Hope that helps.
Ted
------------------------------
Date: Wed, 26 Jul 2006 14:09:42 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Comparing values of multiple hash keys
Message-Id: <ea7t4h.q0.1@news.isolution.nl>
usenet@DavidFilmer.com schreef:
> push @results, "${count}::$word";
OR-Variant:
push(@results, "${count}::$word")
if $count ;
AND-Variant:
push(@results, "${count}::$word")
if $count == keys %keywords ;
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 26 Jul 2006 06:41:23 -0700
From: "Oliver Meister" <oli.meister@gmail.com>
Subject: Count values in multi dimensional array
Message-Id: <1153921283.880665.175160@m79g2000cwm.googlegroups.com>
Dear All
>From an XML file, I have an array (hash) generated [1].
Unfortunately I haven't figured out how i can count the number of
values in the array "Exchange".
I was trying with $var = @arr, key and scalar syntax but also my
attempt try was not successful [2].
With this example [1], I am expecting to have a count of 3 for the Key
"Exchange".
May I ask for a helping hand?
Kind Regards
Oliver
[1]
$VAR1 = {
'InputList' => {
'InputListAction' => 'Replace',
'Instrument' => [
{
'Exchange' => 'SWX',
'Identifier' => '.SSHI',
'IdentifierType' =>
'RIC',
'Description' => 'SPI
TOTAL RETURN'
},
{
'Exchange' => 'N/E',
'Identifier' =>
'AUD6MFSR=',
'IdentifierType' =>
'RIC',
'Description' =>
'Australian Dollar 6 month LIBOR'
},
{
'Exchange' => 'N/E',
'Identifier' =>
'AUD7M=',
'IdentifierType' =>
'RIC',
'Description' =>
'Australian Dollar 7 month Forward'
},
{
'Exchange' => 'N/E',
'Identifier' => 'ZAR=',
'IdentifierType' =>
'RIC',
'Description' => 'South
African Rand Spot'
}
],
'Name' => ' TEST Import'
}
};
[2]
....
$i = 0;
foreach $xChange (
$data->{'InputList'}->{'Instrument'}->['Exchange'] )
{
print $i;
....
------------------------------
Date: Wed, 26 Jul 2006 14:05:46 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Count values in multi dimensional array
Message-Id: <Xns980C66CC44092asu1cornelledu@127.0.0.1>
"Oliver Meister" <oli.meister@gmail.com> wrote in
news:1153921283.880665.175160@m79g2000cwm.googlegroups.com:
> Dear All
>
>>From an XML file, I have an array (hash) generated [1].
>
> Unfortunately I haven't figured out how i can count the number of
> values in the array "Exchange".
> I was trying with $var = @arr, key and scalar syntax but also my
> attempt try was not successful [2].
>
> With this example [1], I am expecting to have a count of 3 for the Key
> "Exchange".
...
> [1]
>
> $VAR1 = {
> 'InputList' => {
> 'InputListAction' => 'Replace',
> 'Instrument' => [
> {
> 'Exchange' => 'SWX',
...
> $i = 0;
> foreach $xChange (
> $data->{'InputList'}->{'Instrument'}->['Exchange'] )
> {
> print $i;
Please don't post stuff like this. Instead, opt for code snippets others
can run by simply copying and pasting.
$data->{'InputList'}->{'Instrument'}->['Exchange']
This is nonsense.
$data->{InputList}->{Instrument} is a reference to an array of
references to hashes. Each of those hashes contains a key called
'Exchange'.
You do not clarify if all you want is the number of instruments, or, if
there is a chance one or more of the instruments might not have an
'Exchange' key.
In any case:
#!/usr/bin/perl
use strict;
use warnings;
my $VAR1 = {
'InputList' => {
'Instrument' => [
{ 'Exchange' => 'SWX' },
{ 'Exchange' => 'N/E' },
{ 'Exchange' => 'N/E' },
{ 'Exchange' => 'N/E' },
],
}
};
my @instruments = @{ $VAR1->{InputList}->{Instrument} };
my $num_ex = grep { exists $_->{Exchange} } @instruments;
print "Number of instruments with 'Exchange' key: $num_ex\n";
__END__
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 26 Jul 2006 14:07:07 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Count values in multi dimensional array
Message-Id: <4ipb8bF4on9uU1@news.dfncis.de>
Oliver Meister <oli.meister@gmail.com> wrote in comp.lang.perl.misc:
> Dear All
>
> >From an XML file, I have an array (hash) generated [1].
>
> Unfortunately I haven't figured out how i can count the number of
> values in the array "Exchange".
"Exchange" appears as a hash key in your structure, with a string
as the value. Nowhere is it associated with an array. The only
array in your structure is the value of key "Instrument" in one
of the hashes. Your statement above makes no sense.
> I was trying with $var = @arr, key and scalar syntax but also my
> attempt try was not successful [2].
Huh?
> With this example [1], I am expecting to have a count of 3 for the Key
> "Exchange".
How so? The key "Exchange" appears in four hashes. Do you only want
to count the cases where the value is "N/E"? That's the only obvious
way I see to arrive at a count of three.
> May I ask for a helping hand?
You'll have to find a way to express your problem more clearly. What
you have written makes no sense.
Anno
------------------------------
Date: 26 Jul 2006 07:27:28 -0700
From: "Oliver Meister" <oli.meister@gmail.com>
Subject: Re: Count values in multi dimensional array
Message-Id: <1153924048.276616.172700@i42g2000cwa.googlegroups.com>
anno4...@radom.zrz.tu-berlin.de schrieb:
...
>
> How so? The key "Exchange" appears in four hashes. Do you only want
> to count the cases where the value is "N/E"? That's the only obvious
> way I see to arrive at a count of three.
>
> > May I ask for a helping hand?
>
> You'll have to find a way to express your problem more clearly. What
> you have written makes no sense.
>
> Anno
Guten Tag Anno
Indeed, I haven't been very clear in my first posting! Reading through
it, makes me think that I can understand it but somebody else. ...At
least, I can understand myself :-)... Also the expected count should
be 4 rather than 3.
Sorry for this everybody.
Anyway:
I've wrote a "workarround hack" for my case which counts the entries of
"Exchange":
$i = 0;
while($data->{'InputList'}->{'Instrument'}->[$i]{'Exchange'})
{
$i++;
print "\n i: $i \n";
print $data->{'InputList'}->{'Instrument'}->[$i]{'Exchange'};
}
What I was realy looking for is something like:
foreach ( $data['InputList']['Instrument']['Exchange'] as $var )
and
count( $data['InputList']['Instrument']['Exchange'] );
Certainly my view is limited on HASH and PERL but couldn't find
something working on google as suggested by A. Sinan Unur in the
previous post. What I've found is counting the scalar or the array with
the "usual" methods. This, in my case, wasn't working. I guess it is
because may construct has hash and array mixed (?).
Gruesse
Oliver
------------------------------
Date: 26 Jul 2006 15:00:36 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Count values in multi dimensional array
Message-Id: <4ipeckF4s457U1@news.dfncis.de>
Oliver Meister <oli.meister@gmail.com> wrote in comp.lang.perl.misc:
> anno4...@radom.zrz.tu-berlin.de schrieb:
[...]
> Anyway:
> I've wrote a "workarround hack" for my case which counts the entries of
> "Exchange":
> $i = 0;
> while($data->{'InputList'}->{'Instrument'}->[$i]{'Exchange'})
> {
> $i++;
> print "\n i: $i \n";
>
> print $data->{'InputList'}->{'Instrument'}->[$i]{'Exchange'};
> }
That only appears to work because all relevant hashes have the key
"Exchange". That is a poor choice of test data. Add a few that
don't have the key and try again. It will give you randomly wrong
(or sometimes correct) results.
> What I was realy looking for is something like:
> foreach ( $data['InputList']['Instrument']['Exchange'] as $var )
> and
> count( $data['InputList']['Instrument']['Exchange'] );
Both the loop and the count function are incorporated in grep().
See "perldoc -f grep" and also see Sinan Unur's suggestion in this
thread.
Anno
------------------------------
Date: Wed, 26 Jul 2006 06:55:00 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <slrnecem0k.5id.tadmc@magna.augustmail.com>
Paul Lalli <mritty@gmail.com> wrote:
> Jack wrote:
>> Would you consider elaborating, or perhaps someone who is willing to
>> help/share.
>
> Implying that I am *not* willing to help or share? You have a very
> bizarre definition of "help".
>
> *PLONK*
You are coming late to the party:
Message-ID: <1148222836.084002.172320@g10g2000cwb.googlegroups.com>
:-(
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 26 Jul 2006 06:56:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <slrnecem42.5id.tadmc@magna.augustmail.com>
Paul Lalli <mritty@gmail.com> wrote:
> Jack wrote:
>> sort @$columnarray;
>
> This does nothing at all.
It is useful only during the winter.
If you keep your tower under your desk, it will help to keep your feet warm!
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 26 Jul 2006 07:49:18 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <slrnecep6e.5om.tadmc@magna.augustmail.com>
Jack <jack_posemsky@yahoo.com> wrote:
> I want to exclude
> from the counting any null values,
> sub uniques
> {
> my %unique = ();
> if (@_ != /^\z/) { $unique{$_}++ foreach @_ } ;
> return keys %unique;
return grep length, keys %unique;
or, since there can only be one anyway:
delete $unique{''};
return keys %unique;
> }
>
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 26 Jul 2006 10:10:46 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: counting number of uniques in a multidimensional array column
Message-Id: <g69mzawlamx.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 25 Jul 2006, jack_posemsky@yahoo.com wrote:
> Ted, great job that works killer... can you tell me, I want to exclude
> from the counting any null values, I tried adding this without
> success..any reply would be appreciated..thanks, Jack
>
> sub uniques
> {
> my %unique = ();
> if (@_ != /^\z/) { $unique{$_}++ foreach @_ } ;
> return keys %unique;
> }
Tad's solution is great, but I just wanted to clarify something. When
you say "null" that actually doesn't mean anything in Perl. Perl
calls undefined values "undef" - this is different from NULL in
C/C++. There are rules about undef and how it's converted to a string
or numeric context, but what's important is to realize that what
you're filtering above is the empty string "", and that's why Tad used
length() in his test.
Interestingly, length(undef) is also 0, which makes Tad's length()
test eliminate undef values as well. For extra credit and fun, figure
out why length(undef) is 0 - you'll learn about the rules I mentioned
above, and you'll be a better Perl programmer for it.
Also, it's good that you posted what you tried even though it didn't
work. People on this newsgroup are very, very helpful when they see
you've tried something on your own. They generally dislike open-ended
questions with vague requirement. This is why you got a good response
from Tad. There's some posting guidelines (look them up on Google
News) posted here regularly, which explain this and more.
Good luck :)
Ted
------------------------------
Date: Wed, 26 Jul 2006 13:52:31 GMT
From: zentara <zentara@highstream.net>
Subject: Re: dumb question about whether hashes get cleared from memory automatically
Message-Id: <7lsec2dort9rdqbs0s8gct33loq829e9da@4ax.com>
On 25 Jul 2006 15:36:21 -0700, "Jack" <jack_posemsky@yahoo.com> wrote:
>Hello,
>
>I am creating several hashes over different large amounts of data as
>part of a loop, and capturing some values from a given hash with each
>iteration. I dont want to keep them around in memory once I get the
>results I am after and then go to the next iteration - I need to be
>concerned about memory usage since I am dealing with a large volume -
>do I need to actually "clear" the hash like once normally does with an
>array or variable or are hashes automatically cleared with the next one
>?? If hashes need to be cleared, what is the syntax ?
>
>Thank you,
>Jack
Well there is no "foolproof method" to be absolutely sure you are
clearing out the hash.
The problem is with refcounts. If a hash value contains a reference to
another object, you have to be careful to remove the object first,
before trying to undef the hash key, or else memory will creep up.
There has been much discussion about this, but the best "rule of thumb"
to follow, is to reuse your hashes as much as possible. Don't undef an
hash then create a new one, but loop thru the hash, and set each key's
value to undef (or ''), then undef the key. Then fill it again with new
keys and values. That will almost always work, by reusing the memory
that the previous hash used, so your program memory will act like a
"peak meter", rising to the value of the biggest hash filled.
Some useful links:
http://perlmonks.org?node_id=336822
http://perlmonks.org?node_id=419754
http://perlmonks.org?node_id=349553
I've only seen 1 example where memory was actually returned to the
system from Perl, it follows below. Generally, peak memory is held
by Perl for reuse.
#!/usr/bin/perl -w
use strict;
$| = 1;
{
my $string;
for ( 1 .. 100000 ) {
$string .= ( 'x' x 1000 );
}
print "press enter to release";
<>;
# note that memory does not get released
undef $string;
print "undefined but still in scope of sub, hit enter\n";
<>;
# if the variable only goes out of scope.
# you *need* to undef it!
}
print "ok,out of scope, press enter to exit";
<>;
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: 26 Jul 2006 05:25:23 -0700
From: "Michael.F123@gmail.com" <Michael.F123@gmail.com>
Subject: garbage collector
Message-Id: <1153916723.205273.4400@p79g2000cwp.googlegroups.com>
Hello!
I write in perl a litle server that start a function on many threads.
The problem is that my aplication crash on a big amount of connection,
but the threads are finishing succesfuly. Do you have any ideea why tje
garbage collector do not delete the objects afther the thread is
finished?
Regards,
Michael
Michael.F123@gmail.com
------------------------------
Date: 26 Jul 2006 15:00:16 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: garbage collector
Message-Id: <3dpec2di8t53a7b3ued8nqpgn0isdbpar4@4ax.com>
On 26 Jul 2006 05:25:23 -0700, "Michael.F123@gmail.com"
<Michael.F123@gmail.com> wrote:
>but the threads are finishing succesfuly. Do you have any ideea why tje
>garbage collector do not delete the objects afther the thread is
>finished?
I'm not an expert at networking. Well, not even a newbie, actually.
Though I'm sure that Abigail, looking at your code, would spot an
error on line 17.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Wed, 26 Jul 2006 14:43:24 +0200
From: Gert Brinkmann <g111@netcologne.de>
Subject: Re: How to send utf-8 data using LWP::UserAgent?
Message-Id: <ea7o1d$apj$1@newsreader2.netcologne.de>
Gert Brinkmann wrote:
> Why does the is_utf8($text,1) routine tells me, that the utf-8 String is
> correct utf-8 even if there is an iso-latin "ö" in the string?
Ok. The string is completely correct. It is tagged as utf8 and it contains
utf8. But the question ist: Why is utf8 converted to iso-latin again, when
writing it into the "binmode'd" file?
Here is a test-script:
-----------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Encode;
my $x = 'gört';
$x = Encode::encode("utf-8", $x);
Encode::_utf8_on($x);
open (my $fh, ">foo.log") or die "could not open foo.log";
binmode $fh;
print $fh "isutf8=", (Encode::is_utf8($x,0)?1:0),
"; correct=", (Encode::is_utf8($x,1)?1:0),";\n";
print $fh $x;
print $fh "\n";
close $fh;
-----------------------------------------------
Execute it gives the following:
$ perl utf8test.pl ; cat foo.log
isutf8=1; correct=1;
gört
I have also tried with
binmode, ":raw"
or ":bytes", but it does not make any difference.
Gert
------------------------------
Date: Wed, 26 Jul 2006 14:01:30 +0100
From: "Alan J. Flavell" <flavell@physics.gla.ac.uk>
Subject: Re: How to send utf-8 data using LWP::UserAgent?
Message-Id: <Pine.LNX.4.64.0607261354230.10915@ppepc87.ph.gla.ac.uk>
On Wed, 26 Jul 2006, Gert Brinkmann wrote:
> Gert Brinkmann wrote:
>
> > Why does the is_utf8($text,1) routine tells me, that the utf-8
> > String is correct utf-8 even if there is an iso-latin "ö" in the
> > string?
>
> Ok. The string is completely correct. It is tagged as utf8 and it
> contains utf8.
Without being able to tell you the precise answer, I suspect this is a
consequence of Perl's attempt to be compatible with earlier versions.
If your string contains nothing more than iso-8859-1 characters, then
in some circumstances it will be treated as such, even though a
utf8-ified version of the string is available to those who ask for it
nicely. If there had been just one character in the string that was
outside of the iso-8859-1 repertoire, I suspect you would have seen
different behaviour.
I *think* a careful perusal of perldoc perlunicode for the relevant
Perl version should help.
But there are some hunches in what I say above, and ICBW. Hope it's
vaguely useful.
------------------------------
Date: Wed, 26 Jul 2006 13:31:14 +0200
From: Holger <spam.trap.never.read@mailinator.com>
Subject: Re: Questions about (non-blocking) sockets
Message-Id: <44c74131.2363247@news.arcor.de>
Hi Xho,
Sorry for not responding sooner. Thank you, and also Uri and Ben, for
your replies.
On 24 Jul 2006 23:06:33 GMT, xhoster@gmail.com wrote:
> Holger <spam.trap.never.read@mailinator.com> wrote:
> > I have working code that is a forever running client and which opens
> > just one connection (with blocking reads) to a server. Generally, it's
> > kind of a ping pong protocol,
>
> What does that mean? One query yields exactly one response?
It's loosely based on Telnet, but without escape sequences. The server
sends more or less continuously data and responds to commands the
client sends. Most of the communication is line based, but
unfortunately with some exceptions.
> > but the server also arbitrarily sends
> > data. I suppose that therefore I haven't run into a deadlock problem
> > yet of not sending often enough data that cause a response in return.
>
> With what is shown, it is hard to say whether you are just lucky so far
> or if your code is really not susceptible to deadlocks. I'd have to see
> the code on the other end too, and know how you are aligning messages.
I couldn't really post more code than the example because the posting
got longer than I intended anyway. But I can gladly supply more
information. And the other end isn't under my control.
> > my $socket = IO::Socket::INET->new( PeerAddr => $RemoteHost,
> > PeerPort => $RemotePort,
> > Proto => 'tcp',
> > Type => SOCK_STREAM )
> > or die "Could not connect to $RemoteHost:$RemotePort: $@\n";
> > my $data;
> > while ( defined $socket->recv( $data, 1028 ) ) {
>
> This seems a little unusual. Usually the client initiates a connection,
> and then initiates the query on that connection. Here, this process
> initiates the connection, but then waits for other side to initiate
> the query. I don't know if that makes this process the client or the
> server.
This server starts by sending a banner and a login prompt, which I
need to wait for. Since my program (theoretically) runs for ever, it
could be viewed as kind of a server, too. Personally, I call something
a server if it's either longer running than the communication partners
or listen()ing for (possibly more than one at a time) new connections.
> Also, does the other end always send records of size exactly 1028?
No. As I understood the parameter, it should be the buffer length and
therefore the maximum of data to be received at that call. I also have
omitted code in the processing part that adds the chunks together and
scans for and then processes the lines, messages or records.
> > I've read to not use recv or sysread together with print on the same
> > socket. Does this apply to the entire socket or only per direction?
> > After all, the above works.
>
> I don't think that mixing them on different legs of the same socket will
> cause problems.
Ok, thanks.
> > I'd like to convert the code into non-blocking call(s), but am a
> > little confused about the exact details, since I've only found
> > examples for the server side with listening sockets. Perhaps, I don't
> > see the wood for all the trees.
>
> Why do you want to do it non-blocking? I can answer some of your technical
> questions without knowing the reason, but knowing why would help us help
> you see the forest for the trees.
In the current code I have a command queue from which I send one
command per incoming and processed message (inner loop not shown in
the example). There isn't a strict one to one relation however. For
some data it's not necessary to send anything, for other I want to
generate multiple commands. Since the server sends data on its own,
which I can use as a heart beat (despite being very irregular), the
danger of getting to the situation where I don't get enough chances to
send something shouldn't be high. (On second thought, this isn't
really a deadlock, so I used the term wrongly.)
> > my $socket = IO::Socket::INET->new( PeerAddr => $RemoteHost,
> > PeerPort => $RemotePort )
> > or die "Could not connect to $RemoteHost:$RemotePort: $@\n";
> > my $select = IO::Select->new( $socket );
> > while ( 1 ) {
> > if ( $select->can_read( $timeout ) ) {
> > unless ( defined $socket->recv( $data, 1028 ) ) {
> > break;
> > }
> > else {
> > # process received $data
> > }
> > }
> > # do stuff, send data
>
> You might want the "send data" to be inside the else. Do you really need
> to send data to the other every $timeout seconds, even if the other side
> hasn't yet responded to your previous queries?
As mentioned above I'd like to be able to send commands independently
from the server sending data. Perhaps, I will insert code to send
waiting data in both places.
> > What exact effects do values undef, 0, and e.g. 5 for $timeout have?
>
> Undef means wait forever for the handle to become readable. 0 means wait
> for zero seconds. 5 means to wait for 5 seconds.
So undef is again blocking, and 0 results in polling, which I guess
should be avoided.
Thanks also for the other answers.
Regards,
Holger
------------------------------
Date: 26 Jul 2006 12:50:09 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Regex query
Message-Id: <4ip6o1F4pecnU1@news.dfncis.de>
it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote in comp.lang.perl.misc:
> $str =~ s/\.(?=.*\.)/\ /g;
Why escape the blank?
Anno
------------------------------
Date: 26 Jul 2006 06:28:58 -0700
From: "it_says_BALLS_on_your forehead" <simon.chao@fmr.com>
Subject: Re: Regex query
Message-Id: <1153920538.406029.78470@b28g2000cwb.googlegroups.com>
anno4000@radom.zrz.tu-berlin.de wrote:
> it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote in comp.lang.perl.misc:
>
> > $str =~ s/\.(?=.*\.)/\ /g;
>
> Why escape the blank?
I heard that in Perl6 the /x modifier would be default for regexes, so
i'm trying to get in the habit of future proofing when i can :-).
------------------------------
Date: 26 Jul 2006 13:31:53 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Regex query
Message-Id: <4ip969F4r8gnU1@news.dfncis.de>
it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote in comp.lang.perl.misc:
>
> anno4000@radom.zrz.tu-berlin.de wrote:
> > it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote in
> comp.lang.perl.misc:
> >
> > > $str =~ s/\.(?=.*\.)/\ /g;
> >
> > Why escape the blank?
>
> I heard that in Perl6 the /x modifier would be default for regexes, so
> i'm trying to get in the habit of future proofing when i can :-).
That may be, but the right hand side of a substitution isn't a regex.
I'm ready to bet you won't have to escape whitespace there, even in
Perl 6.
Anno
------------------------------
Date: 26 Jul 2006 06:40:58 -0700
From: "it_says_BALLS_on_your forehead" <simon.chao@fmr.com>
Subject: Re: Regex query
Message-Id: <1153921258.866755.89620@h48g2000cwc.googlegroups.com>
anno4000@radom.zrz.tu-berlin.de wrote:
> it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote in comp.lang.perl.misc:
> >
> > anno4000@radom.zrz.tu-berlin.de wrote:
> > > it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote in
> > comp.lang.perl.misc:
> > >
> > > > $str =~ s/\.(?=.*\.)/\ /g;
> > >
> > > Why escape the blank?
> >
> > I heard that in Perl6 the /x modifier would be default for regexes, so
> > i'm trying to get in the habit of future proofing when i can :-).
>
> That may be, but the right hand side of a substitution isn't a regex.
> I'm ready to bet you won't have to escape whitespace there, even in
> Perl 6.
ahhhh, you are probably right. i always forget about the RHS...thx for
the correction!
------------------------------
Date: Wed, 26 Jul 2006 10:12:39 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Regex query
Message-Id: <g69irlklajs.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 26 Jul 2006, simon.chao@fmr.com wrote:
anno4000@radom.zrz.tu-berlin.de wrote:
>> it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote in
>> comp.lang.perl.misc:
>>
>>> $str =~ s/\.(?=.*\.)/\ /g;
>>
>> Why escape the blank?
>
> I heard that in Perl6 the /x modifier would be default for regexes, so
> i'm trying to get in the habit of future proofing when i can :-).
I know for a fact that Perl 7 will not have regular expressions, so I
avoid using them ;)
Ted
------------------------------
Date: Wed, 26 Jul 2006 12:31:56 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: using session managment in perl
Message-Id: <4ioumtF4o9bbU1@individual.net>
madan wrote:
> think CGI.pm is part of perl and how does that move away from this
> group topic....
It doesn't. But discussing alternative techniques for session management
is off-topic. (One appropriate group for such a discussion is
comp.infosystems.www.authoring.cgi.)
Helping out to code it in Perl would be on-topic, though.
> if at all u know the logic please do post
As Sinan explained, cookies are typically used for session management.
There are CPAN modules available for such solutions.
> i need to create sessions but not using cookies...
[OT: Then you can use hidden form fields.]
Please feel free to come back if you would encounter difficulties when
coding whatever route you decide to go. But first, please study and
follow the clpmisc posting guidelines:
http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 26 Jul 2006 11:27:07 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: using session managment in perl
Message-Id: <fkIxg.4862$bP5.1471@newsread1.news.pas.earthlink.net>
On 07/25/2006 11:19 PM, madan wrote:
> [...]
> i need to create sessions but not using cookies...
> [...]
Sorry, you'll almost certainly have to use at least one cookie
for sessions to work[0].
These modules may help you with sessions:
CGI::Session
Storable
FreezeThaw
Data::Dumper
--
[0] Unless you use URL session id's--very complicated.
------------------------------
Date: Wed, 26 Jul 2006 10:43:17 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: using session managment in perl
Message-Id: <g697j20l94q.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 26 Jul 2006, madan.narra@gmail.com wrote:
> k..i am using perl 5.6 on windows using apache server....
>
> i need to create sessions but not using cookies...
I think you should look at the HTTP specification. You'll see why
session management without cookies is very difficult - HTTP is a
stateless (mostly) protocol. Perl has lots of ways to deal with
cookies, and you'll have to learn them. If you are under Apache and
just starting to write your code, you can also consider mod_perl,
which usually has better performance, and has built-in facilities for
a lot of the session management. If your code is mostly written
already, it may be difficult to move it to mod_perl if you don't have
a lot of Perl experience.
Ted
------------------------------
Date: Wed, 26 Jul 2006 05:30:51 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: using session managment in perl
Message-Id: <ro7jp3-i7h.ln1@osiris.mauzo.dyndns.org>
Quoth "madan" <madan.narra@gmail.com>:
<snip illiterate wibble>
Please stop changing your From: address.
Ben
--
Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read.
benmorrow@tiscali.co.uk Groucho Marx
------------------------------
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 9526
***************************************