[21920] in Perl-Users-Digest
Perl-Users Digest, Issue: 4124 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 15 11:10:44 2002
Date: Fri, 15 Nov 2002 08:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 15 Nov 2002 Volume: 10 Number: 4124
Today's topics:
Re: -F works on command line but not on #!perl -paF lin <krahnj@acm.org>
Re: A vision for Parrot (Donal K. Fellows)
c2perl <dzluk8fsxsw0001@sneakemail.com>
Re: c2perl <bernard.el-hagin@DODGE_THISlido-tech.net>
Checking for human user with images <addi@umich.edu>
Re: Creating a pop up HTML page in perl <flavell@mail.cern.ch>
Re: Creating a pop up HTML page in perl <bill.kemp@wire2.com>
Re: Cross platform issues <usenet@dwall.fastmail.fm>
Defining a fix port in Registry.pm ??? <no@spam.com>
Deleting from a fixed Length Flat File Database using P (Dan)
Re: Discovering whether qr// needs to recompile an RE (Adrian)
Re: File Handle passing to subroutine does not work whe (Heinrich Mislik)
glob not working in dos <ed.doyle@motorola.com>
Re: installing perl on winxp (Helgi Briem)
ptkdb (debugger) Tabs settings and balloon formatting <cingram@pjocsNOSPAMORHAM.demon.co.uk>
Re: Redhat 8.0 and Perl <willis3140@_no_YAHOO_spam.com>
Re: Socket client/server example not working on Windows (John Ramsden)
summing up file sizes in a dir. <N.Hirani@hgmp.mrc.ac.uk>
Re: summing up file sizes in a dir. <no@spam.com>
Re: summing up file sizes in a dir. <N.Hirani@hgmp.mrc.ac.uk>
Re: summing up file sizes in a dir. <pinyaj@rpi.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Nov 2002 09:55:23 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: -F works on command line but not on #!perl -paF line
Message-Id: <3DD4C469.106816DF@acm.org>
Amir Karger wrote:
>
> Pardon if this is a FAQ, but searching for "-F" or "split" on google
> groups doesn't help much, and I could swear I'm following the docs. I
> can't seem to figure out how to use -F on the #! line, even though it
> works fine on the command line.
>
> foo% perl -palF/:/ -e '$_=join"_",@F'
> 1:2:3
> 1_2_3
You don't have to use split for this.
perl -pe's/:/_/g'
Or
perl -pe'y/:/_/'
Or
perl -072l137pe1
> foo% more a.pl
> #!/usr/local/bin/perl -palF/:/
> $_=join"_",@F;
> foo% perl a.pl
> Scalar found where operator expected at a.pl line 2, at end of line
> (Missing semicolon on previous line?)
> syntax error at a.pl line 2, near "$_"
> Execution of a.pl aborted due to compilation errors.
>
> foo% chmod +x a.pl
> foo% a.pl
> 1:3:4
> 1_3_4
>
> I've tried all manner of -F/x/, -Fx, -F"x", putting the -F in
> different places on the line, splitting on different regexes,
> whatever. I either get errors or in rare cases no output. It happens
> on ActivePerl5.6.1 as well as Solaris Perl5.005_03. Also, if I get rid
> of the -F, then it works fine, splitting on whitespace.
It works fine on my system: Perl 5.6.0 on Linux
John
--
use Perl;
program
fulfillment
------------------------------
Date: 15 Nov 2002 03:52:11 -0800
From: fellowsd@cs.man.ac.uk (Donal K. Fellows)
Subject: Re: A vision for Parrot
Message-Id: <74aa6858.0211150352.8418b96@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> Donal K. Fellows wrote:
>> OK, what sequence of bytecodes would instantiate and invoke those
>> layers? The expositions I've found online so far have been rather
too
>> dry for me to actually see how such a thing could be done.
>
> Umm, err, I don't know... I've merely looked (briefly) at the docs and
> source of Parrot, and never programmed for it. But <handwave>I'm sure
> that it *can* be done</handwave>.
I'm *fairly* sure it can be done. I was just trying to evaluate
whether it could be done with a reasonably small input of effort or
whether it was going to be a really big porting job. (Everything I've
seen so far makes me think that it will be enough effort that I'll
leave it to someone with a commercial interest in having things work
together.)
>> Donal (fed up of hand-waving, particularly in his day job. Must
write
>> code...)
>
> Sorry about the handwaving, but it's the best I can offer. If it can't
> be done now, someone will add it in the future.
It's just that given the size of the semantic disconnect between Tcl
and Parrot, it's pretty clear to me that there's going to be great
amounts of C code (or some other language, I suppose) involved in
building a bridge between the two. Hence my intense interest in
seeing how this might be done, and my irritation at someone saying
"oh, it must be possible". And I was feeling frustrated at cow-orkers
that day too... ;^)
Donal (posting through Google due to sucky local news-server.)
--
[This space unintentionally left blank.]
------------------------------
Date: Fri, 15 Nov 2002 15:52:21 +0100
From: "Jonas Nilsson" <dzluk8fsxsw0001@sneakemail.com>
Subject: c2perl
Message-Id: <ar31mn$nka$1@news.island.liu.se>
Is there a c to perl source convertor?
/jN
------------------------------
Date: Fri, 15 Nov 2002 14:57:23 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: c2perl
Message-Id: <ar320j$nfk$1@korweta.task.gda.pl>
In article <ar31mn$nka$1@news.island.liu.se>, Jonas Nilsson wrote:
> Is there a c to perl source convertor?
Yes. It's called a programmer.
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: 15 Nov 2002 09:49:55 -0500
From: Arnar Mar Hrafnkelsson <addi@umich.edu>
Subject: Checking for human user with images
Message-Id: <xfsvel9mx4z0.fsf@blue.engin.umich.edu>
Sometimes you want to make an image that is 'not trivial' to
OCR by a machine. This is useful to defeat robots that submit
to web forms and such.
Example output of the method I use is at:
http://www.eecs.umich.edu/~addi/perl/Imager/testing_sc.png
The code follows:
#!/usr/bin/perl -w
use Imager;
open(FH,"perl/cross/words.english") or die "Cannot load word list: $!\n";
chomp(@a = <FH>);
$word = $a[rand(@a)];
print "$word\n";
$white = Imager::Color->new("#ffffff");
$font = Imager::Font->new(file=>"fonts/arial.ttf", color=>$white, aa=>1)
or die $Imager::ERRSTR;
$img = Imager->new(xsize=>200, ysize=>100);
$img->string(font=>$font, x=>25, y=>60, size=>40, text=>$word);
$swirl = $img->transform(xexpr=>"x+0.1*y+5*sin(y/15.0+1.57)",
yexpr=>"y+10*sin((x+y-0.785)/15)");
$swirl->write(type=>"png", data=>\$data);
open(OFH, ">testing_sc.png") or die "Cannot open output file: $!\n";
binmode(OFH);
print OFH $data;
close(OFH);
#### end of code
A little note: Of course you need to replace the paths in here with
something that makes sense on your machine. Also, there are of course
better ways to make the images hard to ocr, use a random coefficient
in the transformation, and different functios, different fonts for each
letter, overlay text on top of images, etc.
-- Arnar.
------------------------------
Date: Fri, 15 Nov 2002 12:02:26 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Creating a pop up HTML page in perl
Message-Id: <Pine.LNX.4.40.0211151149150.26181-100000@lxplus071.cern.ch>
On Nov 15, Asad inscribed on the eternal scroll:
> How do I make a new HTML page using a perl script.
By following the same principles that you'd follow from any other
server-side program. There's nothing specific to Perl here; this
appears to be what we call "a stealth CGI question", for which you'd
be better off on the comp.infosystems.www.authoring.cgi group.
> I want it to be a pop up age.
But do your users? The better browsers have an option for users
to turn off this kind of behaviour.
> So my question is, how do I create a pop up HTML page.
By specifying a window target on the HTTP response headers.
But a CGI script only returns a single response per transaction.
> In Javascript we can go:
>
> DisplayOrder = window.open("", "_blank", "toolbar=yes, status=no,
> width=600, height=800");
Not on the server side, you can't. Server-side Javascript is subject
to pretty much the same rules as any other server-side script.
If you want the client to execute some javascript, then you have your
server-side process write that javascript into the generated page.
There's nothing magical about that. The page that's sent to the
client could have been produced from a static file, from a server-side
process, or from a team of penguins pecking holes in cards - the
client doesn't need to know or care just how the server created the
document that they're getting.
Of course, the client may or may not consent to actually executing
that javascript...
> How can I do the same in perl?
With a print statement ;-))
------------------------------
Date: Fri, 15 Nov 2002 11:43:47 -0000
From: "W K" <bill.kemp@wire2.com>
Subject: Re: Creating a pop up HTML page in perl
Message-Id: <S75B9.89$KI3.628@news.uk.colt.net>
Alan J. Flavell <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.40.0211151149150.26181-100000@lxplus071.cern.ch...
> On Nov 15, Asad inscribed on the eternal scroll:
>
> > How do I make a new HTML page using a perl script.
>
> By following the same principles that you'd follow from any other
> server-side program. There's nothing specific to Perl here; this
> appears to be what we call "a stealth CGI question", for which you'd
> be better off on the comp.infosystems.www.authoring.cgi group.
Maybe.
But I'd suggest that the Perl answer is - if you are using lots of JS in the
HTML pages that Perl is supposed to make, look at some sort of templating
mechanism such as a homebrew "read HTML file... insert relevant pieces ...
print", or have a look at whats on CPAN (HTML::Template??)..
------------------------------
Date: Fri, 15 Nov 2002 15:09:53 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Cross platform issues
Message-Id: <Xns92C7676671422dkwwashere@216.168.3.30>
tim <tim@remove.deadgoodsolutions.com> wrote on 15 Nov 2002:
> Well the code runs because it displays the print statements - just doesn't
> pickup any input, so i don't think it's anything to do with the transfer.
> I'll double check the apache config. Thanks for your help, at least it's
> eliminated one of the variables.
Oh, I forgot to mention that I did test it on win2000 and linux (both using
Apache web server).
--
David K. Wall - usenet@dwall.fastmail.fm
"Oook."
------------------------------
Date: Fri, 15 Nov 2002 13:50:57 +0100
From: "Franky" <no@spam.com>
Subject: Defining a fix port in Registry.pm ???
Message-Id: <ar2qjd$1v2$1@rex.ip-plus.net>
Hi all !
I need to connect onto a remote registry through a firewall using
registry.pm, make some stuff there and then disconnect.
I use $HKEY_LOCAL_MACHINE -> Connect ('\\\\'.$target_host, $registry_object)
|| die "Cannot connect to $target_host" ; to connect.
Works fine on machine before the firewall.
Now every time i make a connection to a remote registry, I got a different
source and destination port number.
Is there a possibilty to "tell" the registry.pm to use at minimum a fix
source port ??? (better to define a fix source and destination port)
Thx
Regards, Frank
------------------------------
Date: 15 Nov 2002 04:20:38 -0800
From: thrupwelder@hotmail.com (Dan)
Subject: Deleting from a fixed Length Flat File Database using Perl and HTML
Message-Id: <4d79ea3.0211150420.12f37506@posting.google.com>
Hi, I have the following problem:
I have a HTML page created dynamically which produces a table of member
details for my Website. This includes name, e-mail, password, etc. Each
row of this table is created as a seperate form, in order to post info to
another perl script which controls the deletion of a single record.
When I click delete, the script 'del.pl' is called, but fails to function
correctly. From the command line, the script appears to work fine
(including the file manipulation), except I am unsure how to pass
parameters 'a la POST method' in this way. When called via a Web page,
the script executes up until the files are accessed. If I put the HTML
code before the file access, it is displayed, any HTML after the file
access is ignored. If I place all HTML code after the file access, I get
an "Internal Server Error".
Someone suggested two things to me on the PlusNet discussion forum:
1- There is a problem with the parsing on the post info.
BUT- The post info is fine, I get the HTML to display it for testing
purposes
2- The HTML header is being sent incorrectly.
BUT- Surely HTML wouldn't display at all if this was the case, and
besides, I use the same HTML header for all my scripts and have never had
this problem before.
I thought it may be permissions, but have tried a few different
combinations. It is now 755 for the script and 766 for the data file.
I have included the listing, and I hope someone can help :o)
Dan
********** The listing to the program is below **********
NOTE: You will notice some lines are commented out, this is just me trying
to simplify things. If you think putting the lines back in will help,
please tell me.
#!/usr/bin/perl --
#writetofile.pl program
#From Bob's Notes 6/11/01
#Seperates all values sent from form
#uses a module to define a record structure for the form details
require ("memstruct.pm") || die ("Can't find structure file :$1\n");
#Get POSTed info. from html form - if this prog is called from cgi-bin
read (STDIN, $postinfo, $ENV{'CONTENT_LENGTH'} );
#Split the fields, delimited with &
@infoarray = split(/&/, $postinfo);
#Split pairs of variables in $infoarray into name
#part and value part, getting rid of special http
#chars and replacing with printable chars.
for($n=0; $n<=$#infoarray; $n++)
{
($name, $value) = split (/=/, $infoarray[$n]);
#NOTE for a regular expression,
#the =~ must be adjacent, i.e. no spaces between them!
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
$value =~ tr/A-Z/a-z/;
$infoarray[$n] = $value;
}
$a=0;
# Find and delete address
#Open database file for reading, may need to provide full path
open LOOK, "../members.dat" or die "Can't find file look\n";
#Read all records
while (<LOOK>) {
($fname, $sname, $age, $email, $pass1) = unpack($memstruct, $_);
#($fname, $sname, $age, $email, $pass1) =~ s/\0//g;
#$email =~ tr/+/ /;
#$email =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
#$email =~ tr/A-Z/a-z/;
#When e-mail is found, skip to next element in infoarray1.
if ($infoarray[0] ne $email) {
$newarray[$a] = $_;
$a = $a + 1;
}
else {
next;
}
} #End of While
close LOOK;
#Open temp database file for writing
open TEMP, ">../members.tmp" or die "Can't find file temp\n";
for($a=0; $a<=$#newarray; $a++) {
print TEMP $newarray[$a];
}
close TEMP;
unlink("../members.dat");
chmod "502", "../members.tmp";
rename("../members.tmp", "../members.dat");
&html_header ();
print "<body bgcolor=\"#FFCC22\" text=\"#330000\">\n";
#print "<font face=\"verdana, arial, helvetica, sans-serif\"
size=\"2\">\n";
print "<p>$infoarray[0]</p><h2>Details have now been deleted</h2>\n";
#print "<br><br>\n";
#print "</font>\n";
# Find and delete address
#Print back navigator
print "<br><br><center><a href=\"javascript: history.go(-1)\"><< Click
here to go back</a></center><br>\n";
&html_ender();
exit 0;
sub html_header
{
print "Content-type:text/html \n\n";
# Put up standard HTTP opening line.
# Specify HTML document
print "<HTML> \n\n";
print "<STYLE><!--\n";
print "A {text-decoration:none; color:#330000;}\n";
print "A:hover {text-decoration:underline; color:#330000;} --></STYLE>\n";
# Specify header section
print "<HEAD>\n";
# Put up the title line
print "<TITLE>", "@_", "</TITLE>\n\n";
# End header section
print "</HEAD>\n";
} #end html_header routine
sub html_ender
{
print "\n</BODY>\n\n";
print "</HTML>\n\n";
} #end of html_ender routine
------------------------------
Date: 15 Nov 2002 00:27:09 -0800
From: apronk@csi.co.nz (Adrian)
Subject: Re: Discovering whether qr// needs to recompile an RE
Message-Id: <6b50cc42.0211150027.62e45945@posting.google.com>
[ There is a minor typo in the original script: All 'local' variables
should have been commented out ].
Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote...
> > If qr// compiles the string, then the instance of the variable is the
> > one in the current call. If qr// returnes a cached copy, the
> > instance of the variable is one from a previous call.
>
> I don't really understand your problem, since there is no closure or
> lexical-in-qr in your code example.
The lexical-in-qr is $squirrel. I'm not sure whether the
'{$squirrel .= ", " . ++$counter}'
in the compiled RE counts as a code reference, but it seems to
act like it is binding to the 'my $squirrel' defined in sub compile()
because when I run the script, I get:
compile 1: compile [1], 1, 2, 3, 4, 5
execute 1: execute [1]
compile 2: compile [2]
execute 2: execute [2]
compile 3: compile [3]
execute 3: execute [3]
compile 4: compile [4]
execute 4: execute [4]
compile 5: compile [5]
execute 5: execute [5]
which tells me that each qr// returns the RE where $squirrel was
bound to the $squirrel that was executed on the first call to compile.
> Basically qr// is an operator that returns a precompiled regexp. It's
> evaluated each time it's run, just like the familiar qq//. But its
> return value never changes, even if the value of the variable inside the
> qr// changes (just like qq//). Does it make the thing clearer to you ?
I don't really understand what you mean when you say "It's evaluated
each time" and then "its return value never changes."
What it looks like to me is happenning is that qr// knows whether it
has compiled its argument before and if so, just returns the RE
it generated last time. A useful optimisation so long as the RE
does not have side effects!
My next question is: how can I tell (at the time I execute qr//)
whether it will compile the string in the current context or
whether it will return a compilation from a previous context?
--
Adrian
------------------------------
Date: 15 Nov 2002 09:14:01 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: File Handle passing to subroutine does not work when used with flock
Message-Id: <3dd4bad6$0$31708$3b214f66@aconews.univie.ac.at>
In article <943cec75.0211142125.2c7f85f8@posting.google.com>, pwu@qantas.com.au says...
>if (! open(FILE, "/tmp/log.out")) {
> print "$$: Cannot open /tmp/log.out: $!\n";
> exit(1);
>};
perldoc -f flock
Note that the emulation built with lockf(3)
doesn't provide shared locks, and it requires that
FILEHANDLE be open with write intent.
^^^^^
Hth
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: Fri, 15 Nov 2002 10:45:01 -0500
From: "Ed Doyle" <ed.doyle@motorola.com>
Subject: glob not working in dos
Message-Id: <ar34r9$ppe$1@newshost.mot.com>
Hi,
The small test script below works perfectly in unix but produces nothing in
dos. It shoud list all the files in current directory ending with .c
Any suggestions on why it does not work in dos?
Thanks
Ed
---
#!/usr/bin/perl
my $a;
$a = glob "\*\.c";
for $a(glob "\*\.c")
{
print"$a\n";
}
------------------------------
Date: Fri, 15 Nov 2002 10:58:17 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: installing perl on winxp
Message-Id: <3dd4d1f7.2619814734@news.cis.dfn.de>
On Thu, 14 Nov 2002 20:44:56 -0600, "William Alexander
Segraves" <wsegrave@mindspring.com> wrote:
>"Helgi Briem" <helgi@decode.is> wrote in message
>news:3dd3c762.2551564425@news.cis.dfn.de...
>> On Thu, 14 Nov 2002 06:54:46 -0600, "William Alexander
>> Segraves" <wsegrave@mindspring.com> wrote:
><snip>
>> >You might try installing IndigoPerl, www.indigostar.com, on your XP box.
>It
>> >worked fine when I did this on my son's (similar) XP system.
>>
>> No, if he is only an ordinary user he is not allowed to
>> set up any programs. He has to ask the administrator
>> to allow him to do that.
>
>Helgi, I'd have to defer to your expertise on WinXP. All I know is that I
>was able to install and use IndigoPerl on my son's WinXP Dell system. IIRC,
>I was logged in under my own user name, not his (; but I could be wrong).
>
>What you appear to be suggesting is that a user of WinXP cannot install a
>program under his own user name unless he has admin privileges. Do you know
>that to be true?
OK, WinXP does have a "home" version, I can't remember
what it's called, that basically has no acccess
restrictions, similar to the Win95/98/Me family. Any
user is probably able to install stuff on that. Whether
it is accomplished by putting all users in the Administrator
group or by doing away with access restrictions altogether
by using the FAT system instead of NTFS, I don't know.
The "workstation" version, which is a minor upgrade of
Win2K/NT, does have access restrictions and ordinary
users can *not* install programs or can only write to
registry keys in the "CURRENT USER" hive. I was assuming
this version, but of course there is the "home" type that
I have never used and forgot about.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Fri, 15 Nov 2002 14:31:01 -0000
From: "Clyde Ingram" <cingram@pjocsNOSPAMORHAM.demon.co.uk>
Subject: ptkdb (debugger) Tabs settings and balloon formatting
Message-Id: <ar30cq$gkm$1$8300dec7@news.demon.co.uk>
I have just started using the Perl Debugger ptkdb 1.108, from CPAN, on
Solaris 2.6. (It seems pretty impressive.)
2 questions:
a) How do I configure the code window to expand my source code tabs to 8
spaces?
There is a Tabs menu option, but the manual says nothing about this. I have
tried a variety of values in this:
8
18
8,16,24,32
8 16 24 32
9,17,25,33
9 17 25 33
but none of these have the desired effect. Consequence is that indenting in
the source code window is erratic.
b) How do I prevent the variable dumper from centre-justifying vlaues? When
I put the mouse over the name of a hash, ptkdb displays a balloon showing
the contents of the hash in a multiline display. Unfortunately the text is
centred in the display. Hard to read the contents of a complex hash of
hashes. I would prefer to see values displayed with indent varying
according to nesting level within the hash.
Thanks for advice,
Clyde
------------------------------
Date: Fri, 15 Nov 2002 15:12:17 GMT
From: w i l l <willis3140@_no_YAHOO_spam.com>
Subject: Re: Redhat 8.0 and Perl
Message-Id: <oj3atusa63ukoeu2nmmgdqrsjkldhe6t9o@4ax.com>
jay -
I was printing hello world just a few months ago too. I've learned so
much since then at http://perlmonks.com
On Thu, 14 Nov 2002 12:17:37 -0800, "Jay Calvert"
<jcalvert@no.spam.canspec.com> wrote:
>I know this generally not the place for this type of question but I was
>wondering if anybody else has had this problem.
>
>I have Redhat 8.0 and perl was included (5.8.0)
>
>I do not have much experience with perl but it seems that the following
>should work
>
>test.pl
>--------
>!# /usr/bin/perl
>print "Hello, World";
>--------
>
>I run this file from the command line
>perl test.pl
>
>but nothing happens
>I even tried perl -c test.pl
>and everything came back fine as far as syntax
>
>Any help would be appreciated.
>
>Jay
>
>
------------------------------
Date: 15 Nov 2002 04:19:57 -0800
From: john_ramsden@sagitta-ps.com (John Ramsden)
Subject: Re: Socket client/server example not working on Windows 2K
Message-Id: <d27434e.0211150419.1e4d1f89@posting.google.com>
Rocco Caputo <troc@netrus.net> wrote in message news:<slrnat4u4k.8ma.troc@eyrie.homenet>...
> On 12 Nov 2002 11:23:27 -0800, John Ramsden wrote:
> > I prepared a short pair of prototype socket client-server
> > programs, planning to expand them into what is required
> > for a project I am engaged on at work.
> >
> > On Unix (SunOS) everything works fine with one or more clients
> > each with a TCP socket connection to the server at once, which
> > is the intention.
> >
> > On Windows 2K (using ActiveState Perl v5.6.1 build 631,
> > MSWin32-x86-multi-thread) the pair work fine with a single
> > client; but if _two_ clients are started then the server
> > displays all output from the first client immediately,
> > but buffers all output for the second client (and only
> > displays this when the first client disconnects).
>
> Unless this is an exercise to learn BSD sockets, consider using
> IO::Socket::INET to build them rather than the low-level calls.
Many thanks for your reply, Rocco. I only wish I could use IO::Socket.
But the snag is the server will be receiving a constant stream of event
messages from various clients and has to store these in a different
MySQL database for each. So if everything had to run explicitly in
one process, my server code would be constantly disconnecting from
one database and connecting to another.
(Of course, if there is a nifty way of calling DBI::connect on more
than one database, and switching quickly between them, then this
would avoid the problem. Perhaps one can call DBI::connect on some
database, and then just execute 'use <database>'; statements to
switch databases thereafter. Anyway, I won't speculate further here,
as SQL is off-topic for Perl.)
> What status messages does the server print when the second client
> connects? Tracing through them might help determine the problem.
I did manage to eliminate the output buffering problem on Windows
by replacing every read() and write() socket call by sysread() and
syswrite() resp.
Works fine with one client, then two, then more. _But_ as soon as
a client disconnects (even with the $SIG{CHLD} assignment commented
out in the server code), the server bombs out with a message window
comprising:
perl.exe has generated errors and will be closed by Windows.
An error log is being created
which is a fat lot of use, as it doesn't give any the name or
location of the error log (and I couldn't find any file called
*.log or *.err anywhere in the Perl directory tree). Does anyone
know where this error log goes?
Anyway, I then upgraded from ActiveState perl v5.6.1 to v5.8.0
(beta), hoping that all these problems would go away. But now
things are much _worse_, as the server bombs out with the above
message as soon as the first client tries to connect!
Looks like the signal handling, newly introduced in 5.8.0 as the
readme file says, has gone pear-shaped!
> If fork() is misbehaving under MSWin32-- and it may be, because
> fork() is implemented with threads on that platform-- consider
> using IO::Select to multiplex the connections in a single process.
I really wish the judge in the recent Microsoft anti-trust case
had included in the settlement conditions a caveat that all Windows
versions must incorporate a kosher, copy-on-write fork() call, to be
made publicly available on free upgrade packs within, say, six months.
If not then he/she missed a major trick, as the absence of a fork()
causes huge problems for all kinds of Unix-to-Windows ports, not just
Perl, and its continuing absence seems to me like a clear-cut example
of Microsoft's obstructive tactics that the court case was all about.
Cheers
John Ramsden (john_ramsden@sagitta-ps.com)
------------------------------
Date: Fri, 15 Nov 2002 14:28:14 +0000
From: Naran Hirani <N.Hirani@hgmp.mrc.ac.uk>
Subject: summing up file sizes in a dir.
Message-Id: <3DD5047E.95807728@hgmp.mrc.ac.uk>
Hi,
What's the easiest way to sum up the total size of files in a dir.
I tried stat '*.pl' and various other things but none are satisfactory.
Any ideas or suggestions would be much appreciated.
TIA.
Naran.
------------------------------
Date: Fri, 15 Nov 2002 15:51:00 +0100
From: "Franky" <no@spam.com>
Subject: Re: summing up file sizes in a dir.
Message-Id: <ar31kg$2ti$1@rex.ip-plus.net>
Try this:
use File::stat ;
opendir(LOG_DIR, "$log_dir") ;
foreach $filename(readdir(LOG_DIR))
{
#maybe you can use this --> next if ($filename !~ /.pl/i) ;
$file_size = stat("$log_dir/$filename")->size ;
$file_size_total = $file_size_total + $file_size ;
}
print "Total size is: $total_file_size" ;
Regards Frank
"Naran Hirani" <N.Hirani@hgmp.mrc.ac.uk> wrote in message
news:3DD5047E.95807728@hgmp.mrc.ac.uk...
> Hi,
>
> What's the easiest way to sum up the total size of files in a dir.
> I tried stat '*.pl' and various other things but none are satisfactory.
>
> Any ideas or suggestions would be much appreciated.
>
> TIA.
> Naran.
------------------------------
Date: Fri, 15 Nov 2002 15:06:48 +0000
From: Naran Hirani <N.Hirani@hgmp.mrc.ac.uk>
Subject: Re: summing up file sizes in a dir.
Message-Id: <3DD50D88.2716E446@hgmp.mrc.ac.uk>
Thanks, Franky, I've changed tack now and have decided to use unix
utils, e.g.
@sizes = qx(du *.pl *.c *.h| cut -f1);
while(@sizes) $tot += shift @sizes;
...
can any one spot any probs with this approach?
Is there perhaps an even better way?
I just don't want to read dir if poss.
The above seems to work??
Thanks.
Naran
Franky wrote:
>
> Try this:
>
> use File::stat ;
>
> opendir(LOG_DIR, "$log_dir") ;
> foreach $filename(readdir(LOG_DIR))
> {
> #maybe you can use this --> next if ($filename !~ /.pl/i) ;
> $file_size = stat("$log_dir/$filename")->size ;
> $file_size_total = $file_size_total + $file_size ;
> }
>
> print "Total size is: $total_file_size" ;
>
> Regards Frank
>
> "Naran Hirani" <N.Hirani@hgmp.mrc.ac.uk> wrote in message
> news:3DD5047E.95807728@hgmp.mrc.ac.uk...
> > Hi,
> >
> > What's the easiest way to sum up the total size of files in a dir.
> > I tried stat '*.pl' and various other things but none are satisfactory.
> >
> > Any ideas or suggestions would be much appreciated.
> >
> > TIA.
> > Naran.
------------------------------
Date: Fri, 15 Nov 2002 10:22:05 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Naran Hirani <N.Hirani@hgmp.mrc.ac.uk>
Subject: Re: summing up file sizes in a dir.
Message-Id: <Pine.SGI.3.96.1021115101950.394996A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Fri, 15 Nov 2002, Naran Hirani wrote:
>Thanks, Franky, I've changed tack now and have decided to use unix
>utils, e.g.
>
>@sizes = qx(du *.pl *.c *.h| cut -f1);
>while(@sizes) $tot += shift @sizes;
{ }
>I just don't want to read dir if poss.
>The above seems to work??
While the above way might work, it's not stopping the directory from being
read. The system HAS to access the files' sizes, and it's probably less
efficient to outsource to another program (or two, in your case) than to
do it in Perl:
my $size = 0;
$size += -s for glob("*.pl *.c *.h");
--
Jeff "japhy" Pinyan RPI Acacia Brother #734 2002 Acacia Senior Dean
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
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.
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 4124
***************************************