[13747] in Perl-Users-Digest
Perl-Users Digest, Issue: 1157 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 23 09:05:32 1999
Date: Sat, 23 Oct 1999 06:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <940683911-v9-i1157@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 23 Oct 1999 Volume: 9 Number: 1157
Today's topics:
CPAN modules in RPM format. <carville@cpl.net>
Re: CPAN modules in RPM format. <carville@cpl.net>
Re: CPAN modules in RPM format. <gellyfish@gellyfish.com>
Re: CSV files and file upload strangness. <ian@pengbo.freeserve.co.uk>
Re: file sorting <gellyfish@gellyfish.com>
How can I make to print the times that I input word ? <hmaster@factory.co.kr>
Re: How can I make to print the times that I input wor <marcel.grunauer@lovely.net>
Re: How can I make to print the times that I input wor <hmaster@factory.co.kr>
Re: How can I make to print the times that I input wor <marcel.grunauer@lovely.net>
how to use flock right? <yuval@mypad.com>
Re: how to use flock right? (Martien Verbruggen)
Mac text files vs PC text files -- How are they differe (David Stack)
Re: Mac text files vs PC text files -- How are they dif <flavell@mail.cern.ch>
not Perl, but please read! yoga9900@my-deja.com
Re: not Perl, but please read! (Michel Dalle)
Off Subject : Good News Reader for Windows <aldricht@onslowonline.net>
Re: Off Subject : Good News Reader for Windows (Martien Verbruggen)
Re: One bug with local and one bug with perlbug (Eric Brunet)
Perl on Novell 5.0 <JacekL@w.pl>
Re: Perl vs. REBOL <kbandes@home.com>
Re: SGML/HTML parsing tool (Bart Lateur)
sockets question (Brian StJohn)
Re: sockets question <skilchen@swissonline.ch>
Re: sorting hashes in an array of hashes (Martien Verbruggen)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 23 Oct 1999 08:59:11 +0000
From: Stephen Carville <carville@cpl.net>
Subject: CPAN modules in RPM format.
Message-Id: <381178DF.B34352@cpl.net>
Last night I was trying to locate a perl module on rufus.w3.org but
the CPAN archives seem to have vanished. These modules were all in
RPM format and so were very convenient. Does anyone know what
happened?
--
Stephen Carville
carville@cpl.net
----------------------------------------------------
There are two kinds of people: those who do the work and those
who take the credit. Try to be in the first group; there is less
competition there.
Indira Gandhi
------------------------------
Date: Sat, 23 Oct 1999 09:34:36 +0000
From: Stephen Carville <carville@cpl.net>
Subject: Re: CPAN modules in RPM format.
Message-Id: <3811812C.D6F53FC0@cpl.net>
Never mind, I found them at:
ftp://ftp.cdrom.com/pub/linux/redhat/powertools/CPAN/
Stephen Carville wrote:
>
> Last night I was trying to locate a perl module on rufus.w3.org but
> the CPAN archives seem to have vanished. These modules were all in
> RPM format and so were very convenient. Does anyone know what
> happened?
--
Stephen Carville
carville@cpl.net
----------------------------------------------------
There are two kinds of people: those who do the work and those
who take the credit. Try to be in the first group; there is less
competition there.
Indira Gandhi
------------------------------
Date: 23 Oct 1999 10:25:52 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: CPAN modules in RPM format.
Message-Id: <7us2fg$ecb$1@gellyfish.btinternet.com>
On Sat, 23 Oct 1999 08:59:11 +0000 Stephen Carville wrote:
> Last night I was trying to locate a perl module on rufus.w3.org but
> the CPAN archives seem to have vanished. These modules were all in
> RPM format and so were very convenient. Does anyone know what
> happened?
>
I would not recommend using RPM to install Perl modules as it cannot take
into account local differences in configuration and must by definition
be distributing binaries of any XS components which would be sensitive
to small differences in the runtime environment. Unless you made
some very bad choices while installing Linux you should have everything you
need to build the module from scratch - and quite honestly I dont see
what is difficult in
perl Makefile.PL
make
make test
make install
or even
perl -MCPAN -e'install "Some::Module"'
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 23 Oct 1999 08:08:14 GMT
From: Ian Garlick <ian@pengbo.freeserve.co.uk>
Subject: Re: CSV files and file upload strangness.
Message-Id: <38116CEE.3399FEBE@pengbo.freeserve.co.uk>
lt lindley wrote:
>
> In comp.lang.perl.modules I.J. Garlick <ijg@connect.org.uk> wrote:
>
> :># first line of upload file contains field names
> :># **** comment out the following 3 line ******
> :>$csv->parse(<$filename>) || die "Error in fields description line";
>
> Isn't that <$filename> in list context? I think it slurped in the
> entire file there leaving you nothing else.
>
> $_ = <$filename>;
> $csv->parse($_);
BASH. BASH. BASHBASHBASH (sound of me bashing head on desk).
Yes. Thanks lt. (groan, why didn't I think of that? I need a holiday).
------------------------------
Date: 23 Oct 1999 12:16:08 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: file sorting
Message-Id: <7us8u8$eh7$1@gellyfish.btinternet.com>
On Fri, 22 Oct 1999 21:41:51 -0400 Bob Walton wrote:
> "V.B." wrote:
> ...
>> i have a file,,, myfile.ext, it contains multiple single line entries,
>> each entry contains 7 ";" delimited values,,, id like to sort the file
>> by the 5th value of each entry,,,.
>> if read the sort faq and perlman , but it only confused me ,,, if anyone
>> can point me in the direction of a good example, id be overjoyed!
> ...
> Try:
>
> open IN,"myfile.ext" or die "Oops, open trouble, $!\n";
> print for(sort {(split /;/,$a)[4] cmp (split /;/,$b)[4]} <IN>);
> close IN or die "Oops, close trouble, $!\n";
>
There is that of course but for a larger file the overhead of calling
the splits in the comparison sub is going to drive the execution
time of this way up :
print for ( map { $_->[1] }
sort { $a->[0] cmp $b->[0] }
map { [(split /;/)[4],$_ ] }
<IN> );
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 23 Oct 1999 19:23:28 +0900
From: "Yeong Mo/Director Hana co." <hmaster@factory.co.kr>
Subject: How can I make to print the times that I input word ?
Message-Id: <63Fo47TH$GA.218@news.thrunet.com>
Hi,
I want print, for example, "aaa" on data.db file
$mID = <STDIN>
This is I only know.
open(FILE, ">>data.db") || die "I can't open data.db file \n";
flock (FILE, 2) or die "can't lock data file\n";
print FILE "$mID\n";
close(FILE);
With this code, it prints "aaa" as same times as I input "aaa" like
following;
aaa
aaa
aaa
.....
Here is my question.
How can I make to print only one line of "aaa" and print the times that I
input "aaa" as follows ?
aaa|18
bbb|7
ccc|52
If there is no aaa found, it should print "aaa|1" of course
Thanks in advance.
------------------------------
Date: Sat, 23 Oct 1999 10:26:08 GMT
From: Marcel Grunauer <marcel.grunauer@lovely.net>
Subject: Re: How can I make to print the times that I input word ?
Message-Id: <GpsROBnWUTV651eyJmlXQP1SAiwh@4ax.com>
On Sat, 23 Oct 1999 19:23:28 +0900, "Yeong Mo/Director Hana co."
<hmaster@factory.co.kr> wrote:
> How can I make to print only one line of "aaa" and print the times that I
> input "aaa" as follows ?
> aaa|18
> bbb|7
> ccc|52
>
> If there is no aaa found, it should print "aaa|1" of course
This seems illogical. In any input, there's an infinite number of
words that don't occur. Or maybe you only have a set of words that are
valid input?
For counting the number of words (for some definition of "word"), try:
#!/usr/bin/perl -w
use strict;
my %count;
while (<DATA>) {
$count{$_}++ foreach split;
}
print "$_|$count{$_}\n" foreach sort keys %count;
__DATA__
aaa bbb eee
bbb bbb
ccc aaa
bbb aaa
aaa
prints:
aaa|4
bbb|4
ccc|1
eee|1
--
Marcel, Perl Padawan
sub AUTOLOAD{$_=$AUTOLOAD;s;.*::;;;y;_; ;;print}&Just_Another_Perl_Hacker;
------------------------------
Date: Sat, 23 Oct 1999 20:15:31 +0900
From: "Yeong Mo/Director Hana co." <hmaster@factory.co.kr>
Subject: Re: How can I make to print the times that I input word ?
Message-Id: <gova9YUH$GA.53@news.thrunet.com>
>This seems illogical. In any input, there's an infinite number of
>words that don't occur. Or maybe you only have a set of words that are
>valid input?
>
>For counting the number of words (for some definition of "word"), try:
>
> #!/usr/bin/perl -w
>
> use strict;
> my %count;
>
> while (<DATA>) {
> $count{$_}++ foreach split;
> }
>
> print "$_|$count{$_}\n" foreach sort keys %count;
>
> __DATA__
> aaa bbb eee
> bbb bbb
> ccc aaa
> bbb aaa
> aaa
>
>prints:
>
> aaa|4
> bbb|4
> ccc|1
> eee|1
>
>--
>Marcel, Perl Padawan
>sub AUTOLOAD{$_=$AUTOLOAD;s;.*::;;;y;_; ;;print}&Just_Another_Perl_Hacker;
Thank you Marcel
There is little of your misunderstanding;
I want print only one aaa and bbb....
and when I try aaa or bbb again from the from method
I don't want it to be printed again like;
aaa
bbb
bbb
aaa
I hope it to be printed
aaa|2
bbb|2
If this is illogical as you say, please let me just know it to be printed
like;
aaa
bbb
Not two times od aaa or bbb.
Thanks in advance.
------------------------------
Date: Sat, 23 Oct 1999 11:57:01 GMT
From: Marcel Grunauer <marcel.grunauer@lovely.net>
Subject: Re: How can I make to print the times that I input word ?
Message-Id: <RbAROIsNLzTknePXcvpz5QNrloNL@4ax.com>
On Sat, 23 Oct 1999 20:15:31 +0900, "Yeong Mo/Director Hana co."
<hmaster@factory.co.kr> wrote:
[snip code]
> There is little of your misunderstanding;
> I want print only one aaa and bbb....
> and when I try aaa or bbb again from the from method
> I don't want it to be printed again like;
> aaa
> bbb
> bbb
> aaa
>
> I hope it to be printed
> aaa|2
> bbb|2
Well, that's what the code I posted earlier does.
HTH. HAND.
--
Marcel, Perl Padawan
sub AUTOLOAD{$_=$AUTOLOAD;s;.*::;;;y;_; ;;print}&Just_Another_Perl_Hacker;
------------------------------
Date: Sat, 23 Oct 1999 12:49:28 +0200
From: "Yuval" <yuval@mypad.com>
Subject: how to use flock right?
Message-Id: <7us478$a2s$1@news2.inter.net.il>
Is this pieace of code is the correct way to use flock?
open(FILE,"$file.txt");
flock(FILE,2);
$count = <FILE>;
close(FILE);
is it the same for writing to a file?
BTW what is the "2" after the FILEHANDLE?
thanks
------------------------------
Date: 23 Oct 1999 12:43:21 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: how to use flock right?
Message-Id: <slrn813bfd.dii.mgjv@wobbie.heliotrope.home>
On Sat, 23 Oct 1999 12:49:28 +0200,
Yuval <yuval@mypad.com> wrote:
> Is this pieace of code is the correct way to use flock?
# perldoc -q lock
# perldoc -f flock
# perldoc perlopentut
> open(FILE,"$file.txt");
This is not nice. You should check the return value.
> flock(FILE,2);
This is not nice. You should check the return value. You should use
predefined constants.
> $count = <FILE>;
Oh, god... Not another web counter...
> close(FILE);
> is it the same for writing to a file?
Errr. no. yes. no. yes. What do you mean? You do know that locks do not
care whether you read or write? It's up to you to decide what you want
to do, and you just need to make sure you have the correct lock. You
normally lock exclusively for writes, and non-exclusively for reads. Or
if the read is atomic, you don't even need to bother.
> BTW what is the "2" after the FILEHANDLE?
That is a constant that tells flock how to lock the file. Did you ever
think about reading the documentation (See above)? Oh, and you should
read Randal Schwartz's column. He's got a good entry on this.
(www.stonehenge.com/merlyn/) Oh, and you should read this newsgroup;
this question comes up at least once a week.
Since you have shown so clearly that youhaven't even bothered reading
the documentation, I am not going to type any code for you.
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Sat, 23 Oct 1999 09:41:24 GMT
From: musicstack@hotmail.com (David Stack)
Subject: Mac text files vs PC text files -- How are they different?
Message-Id: <38118006.31989478@news.supernews.com>
I am stumped here. I have two text files. Both are the same ASCII
text file, but one was saved on a MAC and the other on a PC.
I have FTP'ed these two files to my unix server and I now I am trying
to parse each file and print the first line of each file using the
following code:
#!/usr/bin/perl
open (F,"PC_file.txt");
$a=<F>;
print "$a\n\n";
open (D,"MAC_file.txt");
$e=<D>;
print $e;
when I run the above program, I get one line of Text with the PC
version of the file, but with reading the MAC text file, I get the
whole file printed out and not one line of text. I figured this all
had something to do with MACs and PCs using different end of line
characters, so I checked with my favorite hex editor and it ends up
the end of line characters are both the same for each of the two
different files. They are both '0D 0A'. So this leaves me
stumped.
Could someone kindly tell me how to read one line text at a time with
a MAC text file with out reading in the whole file in? Is it
possible?
Many Thanks.
Dave
------------------------------
Date: Sat, 23 Oct 1999 11:59:37 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Mac text files vs PC text files -- How are they different?
Message-Id: <Pine.HPP.3.95a.991023115550.13356A-100000@hpplus01.cern.ch>
On Sat, 23 Oct 1999, David Stack wrote:
> I am stumped here. I have two text files. Both are the same ASCII
> text file, but one was saved on a MAC and the other on a PC.
>
> I have FTP'ed these two files to my unix server
Did you transfer then as text files (aka "ASCII" mode)? If not, why
not, as you say they are text files?
> and I now I am trying
> to parse each file and print the first line of each file using the
> following code:
Recovering from the above error is possible, but not the way you are
going about it. Which do you want - to do the job properly, or to
learn how to code Perl to recover from the blunder?
NB Don't forget that the Mac uses a different 8-bit character coding
than the other platforms. This is sure to bite you sooner or later if
you don't come to terms with it early on.
------------------------------
Date: Sat, 23 Oct 1999 05:20:26 GMT
From: yoga9900@my-deja.com
Subject: not Perl, but please read!
Message-Id: <7urgip$3n1$1@nnrp1.deja.com>
This is a breaking story: http://www.msnbc.com/news/323734.asp?cp1=1
Also: http://www.rickross.com/groups/yogaville.html
I've been researching this group since I first got a flyer from the
group of demonstators outside the Integral Yoga Institute in New York
City last week.
Earlier this year, there were numberous protests against Yogaville,
hundreds of posts and the people of this newsgroup (alt.yoga) shouted
those people down. Shame on all of you! And yet some here still
refuse to believe the atrocities at the hands of this evil organization.
I read there are hunting dogs on the Yogaville property.
Surely, these people are hypocrites!
The audio tape, Television coverage and ongoing media attention to this
story and the MANY attemps at suppression of information by the lawyers
of Yogaville are a CLEAR indication something is very wrong.
How can these people afford to hire FOUR count them 4 lawyers against
that family to see their daughter?
I would never go down there and I would do my best to avoid the Integral
Yoga Institute and the fraud Swami Satchidananda.
In article <21629-3810B016-82@storefull-231.iap.bryant.webtv.net>,
dswgos@webtv.net (myya fungalo) wrote:
> Dear yoga9900, personally I believe the Integral Yoga Institute may be
> the best place for you to learn the yoga of Unconditional Love. It
> doesn't sound like you have much of it.
>
> It sounds like to me you are living a life built on fear and
personally
> I don't believe that's what yoga is about. Yoga, to me, is about love
> and the best way to irradicate your fears, from my point of view, is
to
> go face them. For that reason I suggest you go to Yogaville. Face
your
> fears and learn to love in spite of the world being some other way
than
> you want it to be.---DSW
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 23 Oct 1999 10:18:28 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: not Perl, but please read!
Message-Id: <7us21d$246$1@nickel.uunet.be>
In article <7urgip$3n1$1@nnrp1.deja.com>, yoga9900@my-deja.com wrote:
>This is a breaking story: http://www.msnbc.com/news/323734.asp?cp1=1
<snip>
Have you tried the Meditation::Yoga module from CPAN ?
That might help you reach the right frame of mind.
And be sure to read the Perl documentation, it will leave you detached
from all earthly concerns...
Michel.
------------------------------
Date: Sat, 23 Oct 1999 08:18:55 -0400
From: "aldie" <aldricht@onslowonline.net>
Subject: Off Subject : Good News Reader for Windows
Message-Id: <s139o2v685995@corp.supernews.com>
I do not like outlook news reader... suggestions on a good one ?
maybe one written in Perl ??
TIA
Aldie->Send();
------------------------------
Date: 23 Oct 1999 12:35:04 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: Off Subject : Good News Reader for Windows
Message-Id: <slrn813avs.dii.mgjv@wobbie.heliotrope.home>
On Sat, 23 Oct 1999 08:18:55 -0400,
aldie <aldricht@onslowonline.net> wrote:
> I do not like outlook news reader... suggestions on a good one ?
> maybe one written in Perl ??
\begin[perl]{offtopic}
May I please direct you to the WWW? Yahoo has a pretty large section on
News readers. I'd prefer it if you went to
http://www.xs4all.nl/~js/gnksa/ first, and picked a good one there.
Then, if you have more questions about newsreaders, please use any one
of them to open the group news.software.readers, or any of the *.reader*
or *.newsreader groups, and ask the question there.
\end{offtopic}
\begin[perl]{topic}
If you want to write one in Perl, the modules with in their name might
be a good start. http://www.cpan.org/modules/ [The Module List - section
19)]
\end{topic}
Martien
--
Martien Verbruggen |
Interactive Media Division | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd. | crops where there ain't no crops.
NSW, Australia |
------------------------------
Date: 23 Oct 1999 08:14:06 GMT
From: ebrunet@news.ens.fr (Eric Brunet)
Subject: Re: One bug with local and one bug with perlbug
Message-Id: <slrn812rid.6g9.ebrunet@clipper.ens.fr>
On 18 Oct 1999 11:30:19 -0400, Uri Guttman <uri@sysarch.com> wrote:
>
>perlbug seems to be broken right now (or the mail system behind it
>is). so just mail the bug (and it seems to be one to me) directly to
>perl5 porters at: perl5-porters@perl.org
>
>use a subject which says something like:
>
>BUG: local scope modifies pos()
>
>and mention that perlbug is down.
I have done that the day that message was post, and got no feedback.
Éric Brunet
------------------------------
Date: Sat, 23 Oct 1999 14:15:26 +0200
From: "JacekL" <JacekL@w.pl>
Subject: Perl on Novell 5.0
Message-Id: <7us8tt$r9a$1@helios.man.lublin.pl>
When I execute my script on Novell console
at the end of executing script perl print >>>Press any key to exit <<<
and this proces wait, so long as ................
I want to execute perl script from Cron !
Thx for helping.
Jacek L.
------------------------------
Date: Sat, 23 Oct 1999 12:36:04 GMT
From: Kenneth Bandes <kbandes@home.com>
Subject: Re: Perl vs. REBOL
Message-Id: <3811AC38.611758A1@home.com>
Billy Zhao wrote:
>
> Hi,
>
> I'm working on a project for my programming languages class. Given as how
> REBOL is still relatively new and there're not too many testimonials out
> there, I was just wondering if someone who has used REBOL and/or Perl can
> run down a list of specs I have and tell me which language has the advantage
> over the other?
Sometimes, clpm is like watching a bad movie. The bit-part character
who, it has been hinted, suffers from too much pride and too little
judgement, opens the door to a room full of velociraptors. You
want to shout "don't go in there!" but it's too late and of course
he can't hear you.
Check the clpm archives - we've been down this road (late September).
Surely you don't want to go there again?
Ken Bandes
------------------------------
Date: Sat, 23 Oct 1999 10:04:06 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: SGML/HTML parsing tool
Message-Id: <381287e3.1633963@news.skynet.be>
Tad McClellan wrote:
> Some of the bits of SGML that got axed to create XML are
> exceedingly useful to publishers of large, long-lived,
> complex documents.
We're off topic for this newsgroup, but... while we're at it: what
features?
All I know about SGML is that it is sooo horribly permissive in the
syntax it must accept, that it is impossible to write a generic SGML
parser from scratch. So the whole world is stuck with just one SGML
parser, written by one guy: James Clark. A very unhealthy "monopoly", in
my opinion. (Tell me, honestly: who ever but J. CLark has ever looked
into the source for his parser family?)
At least, it is very well possible to write a complete XML parser from
scratch in just a few days.
--
Bart.
------------------------------
Date: 23 Oct 1999 09:11:23 GMT
From: bsj@fc.hp.com (Brian StJohn)
Subject: sockets question
Message-Id: <7uru3r$3kh$1@fcnews.fc.hp.com>
Hey guys,
I have a server I wrote in perl that passes off connections
to child servers, then merrily waits for another connection.
The problem I'm having is with the data transfer to the child
server - I want it to die if it doesn't recieve data in a given
amount of time, which is doesn't, for some strange reason.
Here's the relevant code :
#lets init the UDP port
my $packed = gethostbyname($keithley);
my $host = inet_ntoa($packed);
eval {
$socket = IO::Socket::INET->new(Proto => 'udp',
PeerPort => 68,
PeerAddr => $host)
or die "Socket to $keithley died: $@\n";
};
if ($@) {
WriteLog "Could not open socket to $keithley: $@";
print "Error: $@\n";
}
WriteLog "Opened UDP port to $keithley";
if (!$frequency) {
#they just want a snapshot of the data
$socket->send($command) or die "send: $!\n";
ProcessReturn();
return;
}
else {
#need to enter a loop here and spit the data back.
#we need to be careful to make sure this process doesn't
#zombie...
#
#frequency is in floating seconds. This loop will continue to pump
#out the data until it's told to stop.
while (1) {
$socket->send($command) or die "send: $!\n";
ProcessReturn();
sleep($frequency);
}
}
sub ProcessReturn {
my $keithley = shift;
my $MAXLEN = 1024;
while (defined($socket->recv($return, $MAXLEN))) {
chomp($return);
if ($return =~ m/=>/) {
return;
}
if ($return =~ m/\?>/) {
print "I don't understand that message.\n";
return;
}
print "$return\n";
}
}
This all works fine and dandy, until the keithley smartlink locks
up and doesn't forward the data anymore. So, I added the following code:
sub ProcessReturn {
my $TIMEOUT = 5;
my $keithley = shift;
my $MAXLEN = 1024;
eval {
local $SIG{ALRM} = sub { die "alarm timed out - no data!" };
alarm $TIMEOUT;
while (defined($socket->recv($msg, $MAXLEN))) {
chomp($msg);
if ($msg =~ m/=>/) {
return;
}
if ($msg =~ m/\?>/) {
print "I don't understand that message.\n";
return;
}
alarm 0;
print "$msg\n";
}
} or die "network timeout...\n";
}
But that dies after the first data element returned, saying it timed
out. I thought it might have something to do with the while loop,
so I changed the code yet again:
sub ProcessReturn {
my $TIMEOUT = 5;
my $keithley = shift;
my $MAXLEN = 1024;
eval {
local $SIG{ALRM} = sub { die "alarm timed out - no data!" };
alarm $TIMEOUT;
$socket->recv($msg, $MAXLEN);
chomp($msg);
if ($msg =~ m/=>/) {
return;
}
if ($msg =~ m/\?>/) {
print "I don't understand that message.\n";
return;
}
alarm 0;
print "$msg\n";
} or die "network timeout...\n";
}
Any suggestions? Do I need to make it clearer what I'm trying to
do?
Thanks,
Brian
------------------------------
Date: Sat, 23 Oct 1999 10:51:49 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: sockets question
Message-Id: <9rgQ3.26167$m4.94723778@news.magma.ca>
Brian StJohn <bsj@fc.hp.com> wrote in:
news:7uru3r$3kh$1@fcnews.fc.hp.com...
>
> But that dies after the first data element returned, saying it timed
> out. I thought it might have something to do with the while loop,
> so I changed the code yet again:
>
> sub ProcessReturn {
> my $TIMEOUT = 5;
> my $keithley = shift;
> my $MAXLEN = 1024;
> eval {
> local $SIG{ALRM} = sub { die "alarm timed out - no data!" };
> alarm $TIMEOUT;
> $socket->recv($msg, $MAXLEN);
alarm 0;
> chomp($msg);
> if ($msg =~ m/=>/) {
> return;
return 1;
> }
> if ($msg =~ m/\?>/) {
> print "I don't understand that message.\n";
> return;
return 1;
> }
> print "$msg\n";
> } or die "network timeout...\n";
>}
>
Two suggestions:
1. The "alarm 0;" line should immediately follow the
"$socket->recv($msg, $MAXLEN);" line.
2. Change the "return;" to "return 1"; or something, otherwise you
always get the die "network timeout...\n".
------------------------------
Date: 23 Oct 1999 12:26:14 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: sorting hashes in an array of hashes
Message-Id: <slrn813afa.dii.mgjv@wobbie.heliotrope.home>
On Fri, 22 Oct 1999 11:51:24 GMT,
c_j_marshall@my-deja.com <c_j_marshall@my-deja.com> wrote:
> my %hash = %$hash_ref;
Two reasons why this is not a good idea, of which the second one is only
of marginal importance.
1) You make a _copy_ of the hash that is referred to by $hash_ref. If
the hash is big, this can eat a lot of memory and take a considerable
amount of cpu time.
2) because of 1), you can't actually modify the contents of the hash you
have anymore. This means that if you need to make local modifications
that need to be reflected in the original, that you need to copy the
hash back. This involves at least the freeing of the original has that
was referred to by $hash_ref, and depending on how you create the new
reference, possibly even another copy.
My advice is to only make copies of hashes and arrays when it is
necessary, or when it is convenient, but never will have much impact on
runtime performance (read, very small arrays/hashes). And even then I'd
probably not do it. Especially not when I already have a reference.
Martien
--
Martien Verbruggen |
Interactive Media Division | Hi, Dave here, what's the root
Commercial Dynamics Pty. Ltd. | password?
NSW, Australia |
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 1157
**************************************