[17305] in Perl-Users-Digest
Perl-Users Digest, Issue: 4727 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 26 00:05:34 2000
Date: Wed, 25 Oct 2000 21:05:09 -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: <972533109-v9-i4727@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 25 Oct 2000 Volume: 9 Number: 4727
Today's topics:
Re: ActivePerl under Windoze 98 <secursrver@hotmail.com>
Re: Basic CGI question <secursrver@hotmail.com>
Re: Confused about behavior of sort command with functi (Gwyn Judd)
Re: Confused about behavior of sort command with functi <elephant@squirrelgroup.com>
Re: File locking (Alan Barclay)
Re: Grep and cut associated data ? New at this ! HELP (Tad McClellan)
Re: Linux: Perl readline... <Jonathan.L.Ericson@jpl.nasa.gov>
Re: Linux: Perl readline... <jeff@yoak.com>
Re: Newbie <secursrver@hotmail.com>
Packaging CPAN Modules With Application asimjalis@my-deja.com
Re: Packaging CPAN Modules With Application <jeff@yoak.com>
Re: Passing data to a script(from a form) <secursrver@hotmail.com>
perl api for verity <jeffdavis@dice.com>
Re: Perl extension in C on Win98 <Jonathan.L.Ericson@jpl.nasa.gov>
Re: perl not resolving dns in a cgi script <elephant@squirrelgroup.com>
Re: perl not resolving dns in a cgi script <peter.sundstrom@eds.com>
Re: Perl, CGI and rsh/rcp in Unix <skuo@mtwhitney.nsc.com>
Re: socket flushing problem <uri@sysarch.com>
socket hang <tommylebrun@yahoo.com>
Re: Spaces to tab <ianb@ot.com.au>
substituting up to the beginning of the line joekind@my-deja.com
two dimensional arrays <mcdonabNO@SPAMyahoo.com>
Re: update a <SELECT> button <elephant@squirrelgroup.com>
variables starting with $:: <hugo@fractalgraphics.com.au>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 26 Oct 2000 03:37:05 GMT
From: "Ed Grosvenor" <secursrver@hotmail.com>
Subject: Re: ActivePerl under Windoze 98
Message-Id: <BFNJ5.25177$rD3.1693432@newsread2.prod.itd.earthlink.net>
Here's another thought. Many of the modules you're probably looking for
aren't available through ActiveState. What I've found is that you have to
go to CPAN for the majority of not-so-standard modules. Now, CPAN works in
Windows/DOS. All you have to do is make sure you have a GNU Zip utility, a
TAR utiltiy, and NMAKE available on your system. Then select as many
mirrors as you can in your config file...because you never know which ones
will be working at any given moment. It's not as pretty as it is in Linux,
but I've managed to get everything I've needed that way. Best of luck to
ya.
Cameron Dorey <camerond@mail.uca.edu> wrote in message
news:39F73B99.D007D219@mail.uca.edu...
> schnurmann@my-deja.com wrote:
> >
> > For some reason, when I try to install perl modules via ppm, it can't
> > find them.
> >
> > If I download them, unzip/untar and then run perl Makefile.PL, Windoze9
> > then complains that the programme performed an illegal instruction. I
> > then have to reboot. Anyone seen this before? Is this a windoze 98
> > problem? I am running ActivePerl 5.6.0, build 618.
>
> Before I answer, take note: if you don't get an answer within one minute
> of posting your question, that's normal, you don't have to post again,
> we'll see it eventually.
>
> Now...
>
> What modules are you trying to install with PPM?
>
> Are you certain that they are available for the 6xx builds?
>
> Where are you downloading them from?
>
> If you are downloading them from ActiveState, you can PPM them from your
> hard drive just like they were at the AS repository. Unzip and read the
> README file. If you are getting them from CPAN because you couldn't
> use/find them at AS, read the HTML FAQ about installing modules which
> came with your Perl.
>
> If you are following the FAQ correctly, you might have a corrupted
> nmake.exe and you need to download a new one.
>
> Cameron
>
> --
> Cameron Dorey
> Associate Professor of Chemistry
> University of Central Arkansas
> Phone: 501-450-5938
> camerond@mail.uca.edu
>
------------------------------
Date: Thu, 26 Oct 2000 01:08:41 GMT
From: "Ed Grosvenor" <secursrver@hotmail.com>
Subject: Re: Basic CGI question
Message-Id: <tuLJ5.24889$rD3.1659681@newsread2.prod.itd.earthlink.net>
I didn't see any replies to this post. I know you asked quite a while ago,
but I figured I'd shoot an answer out anyway. Yes, you can to that. You
will need to have a Web server running on your box. My favorite is Apache
(www.apache.org). And actually, if you want something that works great out
of the box for windows 95/98 (I assume by your question that you're probably
a Windows user since most Linuxes come with Apache and Perl), what I'd
recommend is that you get a perl distribution called Indigo Perl. It's free
and it comes with an Apache server that works right out of the box! If you
go to www.perl.org, and look in the Ports section under Windows ports,
you'll find a link there.
Another useful tool for Windows users is Active State Perl ppm.bat available
from www.activestate.com. It is something of a Windows equivelant of
CPAN.pm.
I'm normally a Slackware guy, but since moving in with my brother, I've had
to adapt to the world of Windows. It's a bit of a pain, but once you get it
all working, it's pretty smooth actually.
Best of luck. I hope this helps. If not you, then maybe some poor Windows
user.
Stephen Dishon <stephen.dishon@northernlight.co.uk> wrote in message
news:39ec6a9a_1@nnrp1.news.uk.psi.net...
> I wish to use a CGI script on my site. Say Matt's Script Archive
> countdown.pl.
>
> Can I setup a cgi-bin DIR on my harddisk to mimic the one on the server
> while I program and test or does it have to be on the ISP's server?
>
> Ta,
>
> Stephen
>
>
------------------------------
Date: Thu, 26 Oct 2000 02:16:09 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Confused about behavior of sort command with function returning list
Message-Id: <slrn8vf4v7.4su.tjla@thislove.dyndns.org>
I was shocked! How could Thomas M. Payerle <payerle@Glue.umd.edu>
say such a terrible thing:
>I encountered some rather unexpected behavior from Perl's sort command when
>trying to sort the return values of a subroutine returning a list. Since
>the perl language interface is usually quite intuitive, I was wondering if
>someone could enlighten me as to perl is not behaving as I would have
>expected (or alternatively, why I should have been expecting what it did:)
>I would have expected the line
>@list2=sort(get_list) to result in @list2 containing ("a","b","c","d"), not
>"get_list". I am also baffled as to the result of adding empty parentheses
nope. You want:
@list2 = sort(@get_list); # note the '@'
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Anything is good and useful if it's made of chocolate.
------------------------------
Date: Thu, 26 Oct 2000 13:18:51 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Confused about behavior of sort command with function returning list
Message-Id: <MPG.14624da2668618b798985a@localhost>
Thomas M. Payerle wrote ..
>I encountered some rather unexpected behavior from Perl's sort command when
>trying to sort the return values of a subroutine returning a list. Since
>the perl language interface is usually quite intuitive, I was wondering if
>someone could enlighten me as to perl is not behaving as I would have
>expected (or alternatively, why I should have been expecting what it did:)
the problem that you're facing is that Perl's sort function can accept a
function name as one of it's arguments .. so it becomes complicated in
the situations that you've shown for Perl to determine exactly what you
mean
and even if it worked the way you've got it below .. it would fail for
people who expect it to assume that it would work the other way around
.. the best idea in this situation is not to rely on the syntax
processing order that Perl uses - and just be explicit in what you mean
#!/usr/bin/perl -wl
use strict;
sub get_list { qw/d a b c/ }
print 'get_list: ' , sort { $a cmp $b } get_list ;
print 'get_list(): ', sort { $a cmp $b } get_list();
print '&get_list: ' , sort { $a cmp $b } &get_list ;
__END__
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: 26 Oct 2000 02:28:45 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: File locking
Message-Id: <972527319.948906@elaine.furryape.com>
In article <8t0ugq$sb2$1@provolone.cs.utexas.edu>,
Logan Shaw <logan@cs.utexas.edu> wrote:
>There's yet another way of doing it.
>
>When writing, lock the file.
>
>When reading, don't lock the file. Instead, check the modification
>time on the file and make sure it's in the past. Then, read the file.
>Then, check the modification time again. If it hasn't changed, great.
>
>If it has, then discard everything you've read from it. Then, wait for
>an appropriate period of time, and start the whole process over again.
>How do you know how long to wait? You can either sleep for a random
>length of time, or (better) put a blocking shared lock on the file and
>then immediately unlock it when you succeed in locking it.
This seems like a lot of hassle to avoid locking, and not gauranteed
to ever complete. Why not just lock the file and be done with it?
------------------------------
Date: Wed, 25 Oct 2000 18:50:42 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Grep and cut associated data ? New at this ! HELP
Message-Id: <slrn8veou2.cl9.tadmc@magna.metronet.com>
On Wed, 25 Oct 2000 14:04:45 -0700, Tim Conrow <tim@ipac.caltech.edu> wrote:
>msalerno@my-deja.com wrote:
>> I need it remove all
>> entries associated with Device/Sub_device IDE1. That includes all of
>> the lines that follow any entry with IDE1 until I hit the next device.
>$/ = ""; # See perlvar
Changes to global variables should be local()ized.
>I'll let you research that. It relies on there being an empty line between the
>paragraphs.
I think the "records" contain a blank line between the Device
and the Sub_device, so paragraph mode won't work.
The OP didn't make clear what a "record" was for his application.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 25 Oct 2000 17:46:34 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Linux: Perl readline...
Message-Id: <39F77EEA.1DFD968F@jpl.nasa.gov>
Alex Fitterling wrote:
> open the file with...
>
> open(TEST,"<file.txt")
You need to test the result of file opens:
open(TEST, "file.txt") or die "can't open file.txt: $!";
> and do somekind of
>
> $LINE=readline(FILE); #where FILE is a file handle
1) Did you mean to change filehandles? (TEST vs. FILE)
2) Is this at the top of your script:
#!/usr/bin/perl -w
use strict; # catches typos, but requires my or our
3) Is this in a loop? Did you know the <FILE> syntax? (perlop) I
almost always use this loop:
while (<FILE>){
my $line = $_; # or just use $_
# do something with $line or $_
};
You should really post a small, self-contained script with inputs and
expected outputs, so that people can see your problem, rather than just
guessing.
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Wed, 25 Oct 2000 19:54:43 +0700
From: "Jeff Yoak" <jeff@yoak.com>
Subject: Re: Linux: Perl readline...
Message-Id: <8t86ec02t8f@news2.newsguy.com>
[posted and emailed]
In article <slrn8veuvd.a0g.mgjv@verbruggen.comdyn.com.au>, "Martien
Verbruggen" <mgjv@tradingpost.com.au> wrote:
> If you really want to use readline:
>
> open(TEST, 'data') or die $!; while (my $line = readline TEST)
> {
> print $line;
> }
> close TEST;
Not on my perl. In addition to not passing strict, it doesn't work
unless you do:
readline *TEST
God... I've been programming Perl for... almost seven years and I didn't
know readline() even existed until I looked it up after seeing the
initial post. Some day I have to read perlfunc end to end.
Cheers,
Jeff
------------------------------
Date: Thu, 26 Oct 2000 02:03:48 GMT
From: "Ed Grosvenor" <secursrver@hotmail.com>
Subject: Re: Newbie
Message-Id: <8iMJ5.25023$rD3.1672162@newsread2.prod.itd.earthlink.net>
There's not really a module as such...I mean, we could go into a really long
explanation, but the easiest thing you can do is go out and spend a few
bucks on the Perl/CGI cookbook by Matt Wright and some other guy. It's
available at any bookstore and it has everything a Web newbie could ever
need...including a really thorough authentication script (with one major bug
I had to fix...but I can't remember at the moment what it was). So go buy
the book, install the script, and then e-mail me with the glaring error and
I'll tell you how to fix it.
Good luck!
<5defcon5@my-deja.com> wrote in message news:8t7el8$tn6$1@nnrp1.deja.com...
> I am writing a web page that has a form taking in a username and
> password. I would like to verify this username and password against
> the system password file. Is there a module or something to help me do
> this and can someone give me an example of how this module is used.
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Thu, 26 Oct 2000 01:41:42 GMT
From: asimjalis@my-deja.com
Subject: Packaging CPAN Modules With Application
Message-Id: <8t824l$egu$1@nnrp1.deja.com>
Here is the problem. I am writing an application in Perl which uses
several CPAN modules. I want the application to be easy to install on
different machines. I don't want to force people to first download and
install the modules from CPAN that my application requires. How can I
do this?
So essentially I want to ship a application.tar.gz file. The end-user
uncompresses/untars it and then runs "make" and then "make install"
and at that point the application should be fully usable.
The build/install should work even if the machine is NOT on-line and if
the user has no root privileges. The required CPAN module files will be
shipped with the application.tar.gz.
The make and make install steps need to somehow do the following
things:
(1) Figure out if the correct versions of the required CPAN modules
are already installed on the machine.
(2) If they are not then unzip and build and install the versions
shipped in the tarball. If the user is not root then the
installation
of these packages should be to the directory where the application
is going to live.
(3) Finally to build and install the application.
My question is this: Is there a module on CPAN that already does this?
CPAN.pm does not appear to fit the bill. The initial configuration
dialog it engages the user in totally violates the idea of automated
installation.
Asim
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 25 Oct 2000 19:44:09 +0700
From: "Jeff Yoak" <jeff@yoak.com>
Subject: Re: Packaging CPAN Modules With Application
Message-Id: <8t85qh02b0p@news1.newsguy.com>
[posted and emailed]
In article <8t824l$egu$1@nnrp1.deja.com>, asimjalis@my-deja.com wrote:
> The make and make install steps need to somehow do the following things:
>
> (1) Figure out if the correct versions of the required CPAN modules
> are already installed on the machine.
> (2) If they are not then unzip and build and install the versions
> shipped in the tarball. If the user is not root then the
> installation
> of these packages should be to the directory where the application
> is going to live.
> (3) Finally to build and install the application.
>
> My question is this: Is there a module on CPAN that already does this?
I've only fairly recently started to experiment with ExtUtils::MakeMaker
and making my own packages that install "normally," but I have what I
hope is a valuable guess. There is no reason you couldn't include the
CPAN modules with your distribution and have them install during the make
install part of the installation. See the "DIR" attribute on
WriteMakeFile(). The only possible snag I can imagine is the case where
someone already has a newer version of the CPAN module you want
installed. You wouldn't want to clobber that.
I've gotten pretty used to Perl doing what I expect. I would test it,
and I'd give at least even money that the Makefile that is generated is
smart enough not to install over a higher version.
If you find that does the wrong thing here, drop me a line because I'd
like to know, and I'll help you figure out how to bully Makefile.PL into
figuring it out for you and doing the right thing.
Cheers,
Jeff
------------------------------
Date: Thu, 26 Oct 2000 03:47:19 GMT
From: "Ed Grosvenor" <secursrver@hotmail.com>
Subject: Re: Passing data to a script(from a form)
Message-Id: <bPNJ5.25205$rD3.1697203@newsread2.prod.itd.earthlink.net>
It looks to me like you're not parsing your form data. In order for your
script to use data passed to it from a Web form, you have to parse it and
read it in.
If you don't understand the docs, go ahead and e-mail me and I'll send you a
simple sub that will do the trick for you.
jason <elephant@squirrelgroup.com> wrote in message
news:MPG.1462364b1fa399a7989853@localhost...
> gopringle@my-deja.com wrote ..
> >I was wondering if you all could help me see the light.
> >
> >I'm testing a script that receives and argument(computer/server name)
> >from the command line and outputs the "APPLICATION" log of that machine.
> >
> >c:>Inetpub\cgi-local>perl showevt.pl kp-papers03
> >
> >-------------------------------------------------------------
> > Thu Oct 19 17:06:39 2000 MSDTC 4 KP-GAM-W098
> >-------------------------------------------------------------
> > Thu Oct 19 17:06:39 2000 MSDTC 4 KP-GAM-W098
> >-------------------------------------------------------------
> > Thu Oct 19 17:06:40 2000 MSDTC 4 KP-GAM-W098
> > .
> > .
> > .
> >
> >***(If the machine name is not specified the log of the current machine
> >is dumped.)***
> >
> >Up to this point everything works fine. The problem that I'm having
> >is that I get a blank page whenever I try to pass the name of the server
> >to the script from a webpage/form.
> >
> >According to what I have read so far I can pass an argument to a script
> >from a form by inseting a "?" and the argument after the url that
> >contains the script on the html code.
> >
> ><a HREF="http://localhost/inetpub/cgi-local/showevt.pl?server">
> >
> >
> >I would appreciate any help regarding this matter. I'm
> >attaching the perl and html code to see if you can catch any errors
> >that I might be making.
>
> read the documentation on the CGI.pm module that you're using in your
> program .. it has countless examples of how to read parameters in
>
> --
> jason -- elephant@squirrelgroup.com --
>
------------------------------
Date: Wed, 25 Oct 2000 22:01:42 -0500
From: Jeff <jeffdavis@dice.com>
Subject: perl api for verity
Message-Id: <39F79E96.3B48BF0A@dice.com>
I'm curious if anyone out there has written a perl api for the verity's
K2 developer kit.
And if so, how did you go about it.
My first instinct is to use xsubs to allow perl to directly interface
with their C api.
However, another option I was considering was to write an interface on
both the C and
perl ends and use sockets to connect from the C api to any of the
available perl sockets,
then I can easily run multiple copies on a web farm. That way I can
more easily and
quickly respond if traffic demand increases and still have a redundancy
aspect if a
single box goes down.
------------------------------
Date: Wed, 25 Oct 2000 18:03:53 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Perl extension in C on Win98
Message-Id: <39F782F9.3B66C16E@jpl.nasa.gov>
David A Ireland wrote:
> I didn't intend to load a new system, but may yet do if this can't be easily
> solved.
Cygwin is pretty slick to install and fairly painless to uninstall. If
you have ever used UNIX you will be right at home.
> Somewhere I've seen advice on the ActivePerl module that involves making
> changes to the ExtUtils library so that Makefile works correctly on Win 98,
> but I couldn't make sense of it - at least not enough to risk messing with
> the libraries.
Try http://www.activestate.com/Products/ActivePerl/Support.html. PPM
might be what you need.
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Thu, 26 Oct 2000 12:38:17 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: perl not resolving dns in a cgi script
Message-Id: <MPG.1462442611f7a9d4989858@localhost>
D.W. wrote ..
>I have a section of code which used the system parameter to resolve an ip
>address to a host name; but its not working. It returns a null or blank
>field.
>
>This is running on an apache server, which has hostname lookups on.
>
>Is there something else I should check or a module that needs to be
>installed?
nope - the code you've shown is working perfectly
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Thu, 26 Oct 2000 16:12:36 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: perl not resolving dns in a cgi script
Message-Id: <8t87ll$6jf$1@hermes.nz.eds.com>
D.W. <dpalmeNOSPAM@unitedtraffic.com> wrote in message
news:8t79o8$hv9$1@nntp9.atl.mindspring.net...
> I have a section of code which used the system parameter to resolve an ip
> address to a host name; but its not working. It returns a null or blank
> field.
>
> This is running on an apache server, which has hostname lookups on.
>
> Is there something else I should check or a module that needs to be
> installed?
It would *really* help if you showed what code you are using.
------------------------------
Date: Wed, 25 Oct 2000 19:44:50 -0700
From: Steven Kuo x7914 <skuo@mtwhitney.nsc.com>
To: joe cipale <jcipale@hotmail.com>
Subject: Re: Perl, CGI and rsh/rcp in Unix
Message-Id: <Pine.GSO.4.21.0010251927421.23744-100000@mtwhitney.nsc.com>
On Wed, 25 Oct 2000, joe cipale wrote:
{ parts snipped }
> I have tried:
> 1) open(PART_FILE, `rsh myhost@data.com cat
> /data_mining/data_path/file.txt`);
> and
> 2) $part.inp = `rsh myhost@data.com cat /data_mining/data_path/file.txt`;
>
> If I use Method #1:
> The page displays okay, but the data I am expecting to see is blank. I
> display the data
> this way:
> @B = <PART_FILE>;
> while ($line = shift(@B)) {
> print $line;
> }
>
> Is there something that I am missing, or, worse yet, something I am trying
> to do that Perl
> will not allow me to do???
>
> Thanks for your help and response.
>
> Joe Cipale
>
>
> If I use Method #2:
> I get an Internal Server Error and a 'Contact Server Admin' message.
(Method #1) I think you want a piped open :
open (PF,'rsh myhost.data.com cat -n /data_mining/data_path/file.txt|') or
die ("Could not open pipe: $!");
(Method #2) Are you using perl -w ? use strict?
I doubt you relly have a variable:
$part.inp
Hint, concatenation is not lvaluable.
Do you login to 'myhost.data.com' or 'myhost@data.com'?
Expressions in backticks are interpolated so I doubt you really wrote
the above.
If anything it should be:
$part = `rsh myhost\@data.com cat -n /data_mining/data_path/file.txt`;
or
$part = `rsh myhost.data.com cat -n /data_mining/data_path/file.txt`;
(Lastly, #3):
Running through cgi as 'nobody', you can not be able to successfully
`rsh`.
--
Steve
------------------------------
Date: Thu, 26 Oct 2000 03:45:43 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: socket flushing problem
Message-Id: <x7d7gomfj0.fsf@home.sysarch.com>
>>>>> "RBN" == Rod B Nussbaumer <bomr@lin01.triumf.ca> writes:
RBN> Been there, done that. The thing I noted is that the output
RBN> to socket functions in perl are based on the write() system
RBN> calls. In the C version I am attempting to duplicate, it is
RBN> exactly the write() function that is employed, and it works
RBN> reliably (although, I now question whether it *necessarily*
RBN> should be reliable). At any rate, it seems to me that if
RBN> write() called from C works, there's got to be a way to get
RBN> write() called form Perl to works on the same host.
here is a simple map:
perl c
---- ----
syswrite write
sysread read
print printf
write no equivilent but it would use printf underneath.
read no equivilent but is it a buffered read.
and perl's read and write have very little to do with each other. this
is one of larry's (few) poor naming decisions.
the cross use of the name write confuses people. perl's write is
formatted and buffered output. only syswrite is unbuffered which is why
it is the best call for sockets.
RBN> my $Sock = IO::Socket::INET->new( PeerAddr => $Address,
RBN> PeerPort => $Port,
RBN> Proto => 'tcp'
RBN> ) || die "IO::Socket \"$Address ($Port)\" : $!\n";
RBN> $Sock->autoflush(1);
new versions of IO::Socket turn on autoflush for you.
also it is poor perl style to use capitalized variables. some like them
for major globals but you aren't doing that.
RBN> print "Socket connected\n";
RBN> while( 1 ){
RBN> if( eof( STDIN ) ){
RBN> last;
RBN> }
RBN> if( defined( $Input = <STDIN> ) ){
RBN> Okay, I've done what you suggest; code sample below. Still, the
RBN> non line oriented packet refuses to to be flushed out.
are you sure the flushing isn't working? do you have proof the server
see the data? have the server print to stdout or a log what it really gets.
RBN> print $Sock $Input; # line oriented, flushed for sure...
RBN> print $Sock $Struct; # should be sent too...
RBN> $Count++;
RBN> }
RBN> #
RBN> # The companion server just echoes everything we send it...
RBN> #
RBN> if( defined( $Input = <$Sock> ) ){
RBN> print "rec\'d : $Input"; # $Struct comes back on next iteration!
note that your structure is not newline terminated. you are reading with
<> which by default read LINES of text. so you never read the echoed
struct as you are waiting for a newline. on the next loop you send the
input line and then see the struct.
solution: use sysread and make the socket nonblocking (with fcntl). use
IO::Select to see if the socket has data to read. i bet your c code
uses read which does not look for a record terminator.
note: never mix <> and sysread on a given file handle unless you know
deep black magic.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Thu, 26 Oct 2000 02:31:19 GMT
From: T <tommylebrun@yahoo.com>
Subject: socket hang
Message-Id: <8t851o$gj7$1@nnrp1.deja.com>
Has anyone had problems with socket hangs? Specifically, I send data to
a server & wait forever for a reply. Is there a way to time it
out? T.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 26 Oct 2000 13:05:56 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Spaces to tab
Message-Id: <39F79184.F45354EA@ot.com.au>
Steven Kuo x7914 wrote:
> Try:
>
> $line =~ s!^( *)!"\t" x int(length($1)/4)!e;
Don't you just hate it when someone posts an identical solution just before
you?
Well, I'm going to gratuitously post my version anyway, the only real
difference being that there is no need for the "int()".
I have also used "<TAB>" instead of "\t" for the sake of the example, so the
output is easy to check.
Regards,
Ian "Me too! Me too!" B.
#!/usr/bin/perl
while (<DATA>)
{
s%^( *)% "<TAB>"x (length($1)/4 )%e;
print;
}
__END__
hello
hello
hello
hello
hello
hello
------------------------------
Date: Thu, 26 Oct 2000 00:57:09 GMT
From: joekind@my-deja.com
Subject: substituting up to the beginning of the line
Message-Id: <8t7vh2$cdm$1@nnrp1.deja.com>
Hi, I need to substitute a string up to a given point.
For example, if I have the following code:
$code = "<B>text</B>,<font size=1>text,<I>text/<U>text";
now I want to substitute the code with nothing before the "," and the
other "," and the "/".
so I want to be able to have the code broken up into this:
<font size=1>text,<I>text/<U>text
<I>text/<U>text
<U>text
I have tried doing this:
$code =~ s/^(.)(.*)(.)$dat4[$a]//;
I find that this code will skip the first comma and substitute from the
second comma to produce this code <I>text/<U>text
Can anyone supply me with the code to do this?
Thanks,
Joe
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 25 Oct 2000 19:11:00 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: two dimensional arrays
Message-Id: <GpMJ5.9630$Wq1.5608761@nnrp5-w.sbc.net>
Hi. (I hope the following is not too much info to swallow...)
I have a question about how to implement a two-dimensional array in Perl.
Specifically, what I am trying to do is create an array named @authors that
is composed of elements of type @author, where @author is defined to be
my @author = ( $lname, $fname, $minit, $suffix, $prefix, $title,
$affiliation, );
So, I imagine I want to declare @authors in this way...
my @authors = (
@author,
);
I will have to grow @authors at run-time.
The data for @authors will be coming from a CSV file that has a rather
complex structure (Note: I'm using the Text::CSV_XS module). The syntax of
the "authors" field looks like this:
"author1|author2|author3|...|authorN"
and the syntax of the "author" sub-fields looks like this:
lname,fname,minit,suffix,prefix,title,affil
I've declared the following CSV objects to handle the parsing of the
"authors" and "author" fields:
------------------------
# create a new CSV object for the author sub-fields
my $objCSVAuthors = Text::CSV_XS->new({
'quote_char' => '',
'sep_char' => '|',
'binary' => 1
});
# create a new CSV object for the name components sub-field
my $objCSVAuthor = Text::CSV_XS->new({
'quote_char' => '',
'sep_char' => ',',
'binary' => 1
});
-------------------------
The first thing I do is read in one record from the CSV file, parse it, and
put all the fields in the @field array. $field[8] holds the value in the
"authors" field. Then I parse the "authors" field in this manner...
# parse the "authors" field in order to get at the "author" sub-fields
#
if ($objCSVAuthors->parse($field[8])) {
my @authors_field = $objCSVAuthors->fields;
So, @authors_field is an array of the unparsed "author" sub-fields. Next, I
size the @authors array based on the number of "author" sub-fields...
# size the @authors array
#
$size = scalar(@authors_field);
@authors = (0) x $size;
Then, I increment the x-dimension index of the 2D array (initialized to 0
earlier)...
$nn++;
Finally, I loop over...
# loop over each element in @author_field (i.e. each "author"
sub-field)
# and initialize the @authors array
#
for ($y = 0; $y < $size; $y++) {
# parse this "author" field into the @authors array
#
if ($objCSVAuthor->parse($authors_field[$y])) {
@author = $objCSVAuthor->fields;
$authors[$nn][$y] = \@author;
}
$nn++;
} # end for
}
But, I get the following error:
"Can't use string ("0") as an ARRAY ref while "strict refs" in use at
txt2xml.pl line 839, <CSV> line 1."
It is possible that I am either screwing up on my understanding of
multi-dimensional arrays or dereferencing in Perl... or both. But I am going
cross-eyed trying to debug my problem...
Any help appreciated!
Brian
------------------------------
Date: Thu, 26 Oct 2000 13:06:09 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: update a <SELECT> button
Message-Id: <MPG.14624aab6583f583989859@localhost>
Maxime wrote ..
>I am programming PERL (and Javascript with perl)
>I have two <SELECT> buttons with different <OPTION>. The stuff is that i
>choose a option in the first button, then by a "onchange" event i have
>to submit the same page but now the second option button is updated. I
>mean that all the second option's button depends on the choice of the
>first one. how can i do this with perl ? sending a parameters with the
>submit ? is CGI.pm will do that ?
yes - CGI.pm will help you read a parameter from a SELECT field .. read
the CGI.pm documentation by typing the following on the command line
perldoc CGI
for more information on the perldoc utility type
perldoc perldoc
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Thu, 26 Oct 2000 10:12:33 +0800
From: Hugo Bouckaert <hugo@fractalgraphics.com.au>
Subject: variables starting with $::
Message-Id: <39F79311.FCD2B8B5@fractalgraphics.com.au>
Hi All
I know how the double colon is used to access parts of larger modules,
such as:
use Text::Wrap;
But I have a set of perl modules interacting with each other, and many
of the variables are defined as follows:
$::currentquery = $::db->query($str);
I suspect that both the variable $::currentquery and the object
$::db->query($str); are global in scope, but this leaves me with another
problem:
I have a set of form elements specified in one script
<FORM NAME=changeform METHOD=POST ACTION etc..>
<INPUT TYPE=\"text\" NAME=\"assigned_to\">
The form element with name "assigned_to" can be accessed by other perl
programs. For example, if you want to assign whatever was put in that
form to a variable in another perl program, you use:
my $somevariable = trim $::FORM{'assigned_to'});
Yet for other variables given global scope (with $::), you canot assign
the value to another variable.
Can anyone enlighten me on why this can't be done and what $:: exactly
does?
Any help will be much appreciated.
Thanks
Hugo
--
Dr Hugo Bouckaert
R&D Support Engineer, Fractal Graphics
39 Fairway, Nedlands Western Australia 6009
Tel: +618 9386 7917
Email:hugo@fractalgraphics.com.au
Web: http://www.fractalgraphics.com.au
------------------------------
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 4727
**************************************